Topic 8

Dates: 3/8/2017
Start-up and Run Levels. Scheduled jobs (at, cron)
Linux System Administration


Scheduled periodical jobs: cron

To schedule jobs to execute repetitively at regular intervals, use cron. Daemon crond runs every minute and searches /var/spool/cron for crontab files and checks /etc/crontab and /etc/cron.d.
/etc/crontab:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6    * * 0   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly
52 6    1 * *   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly
 
Format: (time) (user) (executable)
time: minute (0-59), hour(0-23), day of the month(1-31), month(1-12), week day (0-6) starting with Sun.
Example:
25 10 * * * root  /root/scheduled.sh   # runs /root/scheduled.sh every day at 10:25
25 10 * * 6 root  /root/scheduled.sh   # runs every Sat. at 10:25
*/5 * * * 6 root  /root/scheduled.sh   # runs every 5 min on Sat.

On systems that don't run continuously, such as desktops and laptops, a scheduled in cron job may miss its time to run. Another scheduler, anacron, can be used to run periodically and when the system boots up.
/etc/anacrontab:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# These replace cron's entries
1       5       cron.daily       nice run-parts --report /etc/cron.daily
7       10      cron.weekly      nice run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly nice run-parts --report /etc/cron.monthly
Format: (period in days) (delay in minutes) (job-identifier) (command)
Usually, anacron runs at system startup and daily at 7:30 a.m. by cron.


Take me to the Course Website