Hello everyone,
I need to have a python script running every minute to send a heartbeat broadcast.
I have developed this sript and it works just fine when I start it from the shell.
Next step was to actually add it to the cron list.
So I have been looking on the net and I saw that should be possible by using crontab -e.
So that’s what I’ve done, resulting in the following :
Hello everyone,
I need to have a python script running every minute to send a heartbeat
broadcast.
I have developed this sript and it works just fine when I start it from the
shell.
Next step was to actually add it to the cron list.
So I have been looking on the net and I saw that should be possible by
using crontab -e.
So that's what I've done, resulting in the following :
The first line in your crontab runs once per hour at 30 minutes past the top of the hour. The second line also runs once per hour, but runs 1 minute past the top of the hour. *NOT* once every minute as you desired.
Crond runs *only* once every minute (finest resolution possible), so if you want a cron job to run once every minute, then you need to set the fields as follows:
* * * * * /home/root/keep_alive.py >> cronjob.log
And check to make certain that your script actually resides in the directory path you have given (/home/root/). The 'root' account's home directory is /root, not /home/root, so to have /home/root you must have performed a mkdir to create that root subdirectory under /home. Also be aware that plain old users CANNOT run scripts that require 'root' permissions. They must be run out of the system crontab configured in /etc/crontab.
Also verify that the permissions are set correctly on your python script so that it is executable. 'ls -al keep_alive.py' will show the permissions. 'chmod u+x keep_alive.py' will turn on the execute bit for this file to be run as the User.
Hope this helps!
--- Jay Nugent WB8TKL
UNIX/Linux System Administration instructor
Washtenaw Community College - Ann Arbor, Michigan
Hello everyone,
I need to have a python script running every minute to send a heartbeat
broadcast.
I have developed this sript and it works just fine when I start it from the
shell.
Next step was to actually add it to the cron list.
So I have been looking on the net and I saw that should be possible by using
crontab -e.
So that's what I've done, resulting in the following :
It is always a good idea to add an absolute path, and if u consider
Jay's tips, the correct for every minute is:
* * * * * /pathtopython/python /home/root/keep_alive.py >>
/home/root/cronjob.log
or if keep_alive.py is an executable simply
* * * * * cd /home/root/; keep_alive.py >> cronjob.log
or ....