简体   繁体   中英

Daemon with python 3

I am writing a script in python3 for Ubuntu that should be executed all X Minutes and should automatic start after logging in. Therefore I want to create a daemon (is it the right solution for that?) but I haven't found any modules / examples for python3, just for python 2.X. Do you know something what I can work with?

Thank you,

I would simply make the script, and have it somewhere, and then add a line to the crontab of the user who you want to run the script. This may be the root.

sudo crontab -e 

To start the editor of the crontab

X * * * *    /usr/bin/python /path/to/the/script

This way the script will be executed every X minutes. No need to daemonize, no need to make your own timer in the script.

Suppose for python script name is monitor . use following steps:

  • copy monitor script in /usr/local/bin/ ( not necessary )

  • Also add a copy in /etc/init.d/

  • Then execute following command to make it executable

    sudo -S chmod "a+x" "/etc/init.d/monitor"

  • At last run update.rc command

    sudo -S update-rc.d "monitor" "defaults" "98"

this will execute you monitor whenever you login for all tty .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM