2

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,

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
Eknoes
  • 508
  • 1
  • 11
  • 24
  • 2
    yes daemonizing your python script is good for that purpose. This [SO Answer](http://stackoverflow.com/questions/7675573/using-python-daemonizing-a-process/12844368#12844368) has great resource to look at, it will also work for python 3. – Rahul Gautam Dec 05 '12 at 11:11
  • 1
    And if you just need it for ubuntu then goto System -> Prefrences -> Startup Application . Add you python command here. – Rahul Gautam Dec 05 '12 at 11:14
  • 1
    Thanks for your answers, the link looks very good :) – Eknoes Dec 05 '12 at 11:17
  • 1
    Welcome buddy, its the beauty of SO now it contains almost every thing that we need to know. – Rahul Gautam Dec 05 '12 at 11:19

2 Answers2

5

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.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
1

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.

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208