Upload
primeteacher32
View
193
Download
0
Embed Size (px)
Citation preview
Cron Jobs
Crontab• Like the windows task scheduler
• Unix’s have a traditional job scheduling daemon named cron• crontab is the command
used to display/edit a user’s crontab file
Each user has their own• One crontab per user stored in
/var/spool/cron/crontabs
• This directory is not typically open for user viewing
• Users can edit their file with a $crontab –e command
Crontab Record Format• Format is generally ‘at this time on this date run this
command’
MM HH DM MN WK /~/bin/Command
MM - MinutesHH - HourDM – Days of MonthMN - MonthWK – Days of Week
Examples#run every minutes of every hour of every day of the month or every month and every day of the week• ***** /~/bin/constant.txt
# run five minutes after midnight, every day • 5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul • 15 14 1 * * /~/bin/monthly
# run at 10 pm on weekdays, annoy • Joe 0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?
%
More Examples#using a ‘-’ to mean all values in between#adding a ‘/2’ means to skip values• 23 0-23/2 * * * echo "run 23 minutes after midn, 2am,
4am ...”
#using either ‘sun’ or 0 or 7 for Sunday• 5 4 * * 0 echo "run at 5 after 4 every sunday"• 5 4 * * sun echo "run at 5 after 4 every sunday"
Commands•$crontab –e #edit user’s crontab file•Default editor is Vi, change to default to nano:• export VISUAL=nano; crontab –e• export EDITOR=nano crontab –e
•$crontab –l #list user’s crontab file• If you’re logged in as root and would like to view or edit a user’s file,• #crontab –u <username> -l or -e