Scheduling Tasks


• Each user has a crontab (cron table) which is a table that you configure schduled tasks

crontab -l                  # list crontab of user
crontab -e                  # edit user specific crontab


# Example
# /var/spool/cron/crontabs/ (user)
# m h dom mon dow command
15  10  *   *   3-5 echo "$(date): checking in." >> /home/$(whoami)/mycheckin


• 6 fields need to be defined in crontab
◇ minutes
◇ hour
◇ day of month (dom)
▪ * means every day
◇ month of year (mon)
▪ * means every month
◇ day of week (dow)
▪ range: 1 to 7, 1 means monday
◇ user
▪ exist in system-wide crontab only (see below)
◇ command
▪ interpreted by sh

• User defined crontabs are stored in /var/spool/cron/crontabs/ . One for each user
• Package specified crontabs are stored in /etc/cron.d
• Syetem-wide crontab is stored in /etc/crontab

sudo ls /var/spool/cron/crontabs/               # user specific
sudo ls /etc/cron.d                             # program specific
sudo ls /etc/crontab                            # system-wide


# Examples:
# /etc/crontab (system-wide)
# m h dom mon dow user command
15  10  1-10/2  *   5   root    echo "$(date): checkin" >> /var/log/croncheck.log
# /2 means every 2 days

15  10  1,2,3,7  *   5   root    echo "$(date): checkin" >> /var/log/croncheck.log


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

White List


• Create /etc/cron.allow to lock out cron

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Edit a Specific User Crontab (for root)


• Instead of editing /var/spool/cron/crontabs/ for a specific user, edit via the following

# Edit with root privilege
crontab -e -u username


Index