Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Dec 2003
    Location
    Brisbane, Australia
    Posts
    65

    Default How to set cron job through shell ?

    An entry in cron is made up of a series of fields, much like the /etc/passwd
    file is, but in the crontab they are separated by a space. There are normally
    seven fields in one entry. The fields are:

    minute hour dom month dow user cmd

    minute This controls what minute of the hour the command will run on,
    and is between '0' and '59'
    hour This controls what hour the command will run on, and is specified in
    the 24 hour clock, values must be between 0 and 23 (0 is midnight)
    dom This is the Day of Month, that you want the command run on, e.g. to
    run a command on the 19th of each month, the dom would be 19.
    month This is the month a specified command will run on, it may be specified
    numerically (0-12), or as the name of the month (e.g. May)
    dow This is the Day of Week that you want a command to be run on, it can
    also be numeric (0-7) or as the name of the day (e.g. sun).
    user This is the user who runs the command.
    cmd This is the command that you want run. This field may contain
    multiple words or spaces.

    If you don't wish to specify a value for a field, just place a * in the
    field.

    eg:

    01 * * * * root echo "This command is run at one min past every hour"
    17 8 * * * root echo "This command is run daily at 8:17 am"
    17 20 * * * root echo "This command is run daily at 8:17 pm"
    00 4 * * 0 root echo "This command is run at 4 am every Sunday"
    * 4 * * Sun root echo "So is this"
    42 4 1 * * root echo "This command is run 4:42 am every 1st of the month"
    01 * 19 07 * root echo "This command is run hourly on the 19th of July"


    cron files have been kept in /var/spool/cron/. Every user can potentially have a crontab file for running jobs on a regular basis. Those files are kept here named as the username. The system crontab file has been named root, which, of course, is also a user on the system.


    If you want to set cron job for root user please follow the given instructions:

    #cd /var/spool/cron
    #vi root

    59 11 * * * root backup.sh

    (Will run backup.sh at 11:59 every day)


    59 11 * * 1,2,3,4,5 root backup1.sh

    (Will run backup.sh at 11:59 Monday, Tuesday, Wednesday, Thursday and Friday,
    as will -> 59 11 * * 1-5 root backup.sh )


    If you want to set cron job for virtual user please follow the given instructions:


    #cd /var/spool/cron
    #vi User_Name

    5 0 * * * php $HOME/daily_job.php >> $HOME/tmp/out 2>&1

    (This says run this job once a day (5 min after midnight). The job to run is $HOME/daily_job.php Any output from this job is appended (>>) to the file $HOME/tmp/out and Standard error (2) is also sent to standard output which means it also gets appended to the file.
    Thanks,

    Bill, Lover & Strong supporter of Cpanel.

  2. #2
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,495

    Default

    If you want to set cron job for virtual user please follow the given instructions:


    #cd /var/spool/cron
    #vi User_Name
    No. You should never edit a crontab file directly like that within /var/spool/cron (don't you read the warnings at the top of the file ).

    If you want to edit a users crontab from the root shell, you should always use:

    crontab -e -u <USERNAME>
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

  3. #3
    Member PWSowner's Avatar
    Join Date
    Nov 2001
    Location
    ON, Canada
    Posts
    2,994

    Default

    If you edit a cron file directly, it won't even take effect until you restart the cron daemon. Chirpy is correct in how to edit a cron file.

    Like I said in the longer thread, I'm all for how-to's, but only post a how-to if you know what you are posting.
    Mike
    WHM and cPanel Scripts (join our "Scripts Club")
    D/A Photography

  4. #4
    Member Roy@ENHOST's Avatar
    Join Date
    Mar 2002
    Location
    Los Angeles California
    Posts
    495

    Default

    So if I edit my cron file using Notepad then uploaded it, all it takes is a /etc/rc.d/init.d/crond restart am I right?


    Quote Originally Posted by squirrel
    If you edit a cron file directly, it won't even take effect until you restart the cron daemon. Chirpy is correct in how to edit a cron file.

    Like I said in the longer thread, I'm all for how-to's, but only post a how-to if you know what you are posting.
    = = = = = = = = = = = = = = = = = =
    Cpanel XP Evolution (Add DOZENS of functions to your Cpanel NOW!!!) - 21 Languages, User Friendly Interface, Feature Enabled, Highly Customizable, Create Popup Once window, Language Aware, Flash Tutorials, Theme Changer,Integration with Modernbill,WHM AutoPilot,ClientExec,LPanel&WHOISCart

  5. #5
    Member PWSowner's Avatar
    Join Date
    Nov 2001
    Location
    ON, Canada
    Posts
    2,994

    Default

    Quote Originally Posted by Roy@ENHOST
    So if I edit my cron file using Notepad then uploaded it, all it takes is a /etc/rc.d/init.d/crond restart am I right?
    Correct. It's not the proper way, but it's how I did it for a bit until I learned the right way.
    Mike
    WHM and cPanel Scripts (join our "Scripts Club")
    D/A Photography

Similar Threads & Tags
Similar threads

  1. Need to set max cron job limit
    By thewebhosting in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 05-15-2008, 03:33 AM
  2. Cpanel unable t set Cron job.
    By SACHIN in forum New User Questions
    Replies: 4
    Last Post: 10-10-2006, 05:45 AM
  3. How to set cron job through shell ?
    By billau in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 07-17-2004, 05:10 PM
  4. Cron Job in shell
    By netlook in forum cPanel and WHM Discussions
    Replies: 7
    Last Post: 04-20-2004, 06:14 PM
  5. Cron job not working when set up through CPanel?
    By avara in forum cPanel and WHM Discussions
    Replies: 13
    Last Post: 09-04-2002, 06:10 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube