January 21st, 2013, 03:09 PM
CentOS Cronjob Assistance
I am attempting to set up a cronjob on my new CentOS server, but I am having trouble getting it to work. I logged in as su and edited the crontab file to read the following
with the only line I added being the 40 * *.... I also ran the "/sbin/service crond start" command to start cronjobs, and it executed without return any errors.
# For details see man 4 crontabs
40 * * * * python /home/hojoff79/onlinetest.py
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
I have run that exact line "python /home/hojoff79/onlinetest.py" from the etc folder where crontab is saved, and it executed perfectly, so I do not understand why it won't execute automatically.
Also, I am self taught so a lot of my programming is trial and error, but I am not sure how to see a log of how a crontab executed to see if it is giving any errors or not, is there a log somewhere I could look at to hopefully get an idea of why is is not working?
January 21st, 2013, 03:41 PM
January 21st, 2013, 04:47 PM
Thank you spacebar for that advice, very helpful. I reviewed the log and it is not running the task (or even attempting to) every hour like it should be. My only hint is the code on startup had the following line related to the crontab file:
I am assuming that this relates to why it is not running every hour like it should be. Can anyone tell me what this line means in relation to my code?
crond: (CRON) bad username (/etc/crontab)
Also, i noticed that this line referencing crontab on startup is the only time that it mentions the file. Does that mean that after I make changes to the crontab file that I need to run the "/sbin/service crond start" command again to get it to review the file and add the new/updated tasks?
January 21st, 2013, 09:03 PM
January 30th, 2013, 04:24 PM
I'd guess it's producing the bad username error as it's taking 'python' to be the user. Look at the last line of your crontab quoted above and you'll see that user comes after when to run.
You should generally always the full path of where Python (or bash, ksh, whatever) resides, e.g.
40 * * * * /usr/bin/python /home/hojoff79/onlinetest.py
The No Ma'am commandments:
1.) It is O.K. to call hooters 'knockers' and sometimes snack trays
2.) It is wrong to be French
3.) It is O.K. to put all bad people in a giant meat grinder
4.) Lawyers, see rule 3
5.) It is O.K. to drive a gas guzzler if it helps you get babes
6.) Everyone should car pool but me
7.) Bring back the word 'stewardesses'
8.) Synchronized swimming is not a sport
9.) Mud wrestling is a sport