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.



LinkBack URL
About LinkBacks
Reply With Quote
).





