Question

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,

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top