#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    17
    Rep Power
    0

    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

    Code:
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    HOME=/
    
    # 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
    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.

    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?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    225
    Rep Power
    41
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    17
    Rep Power
    0
    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:

    Code:
    crond[20277]: (CRON) bad username (/etc/crontab)
    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?

    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?
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    225
    Rep Power
    41
    Are you using 'crontab -e' to add/change a crontab entry OR are you editing the /etc/crontab file?

    The /etc/crontab file is slightly different format than a normal
    per-user crontab file.
    See info here:
    http://lists.fedoraproject.org/piper...ry/392598.html
  8. #5
  9. Providing fuel for space ships
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2004
    Location
    nr Edinburgh, Scotland
    Posts
    14,382
    Rep Power
    3848
    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.
    Code:
    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

IMN logo majestic logo threadwatch logo seochat tools logo