Cron

From Schmid.wiki
Jump to: navigation, search

Contents

System-wide Cron Configuration

# vim /etc/crontab

Example configuration:

# 0    *   * * *    root  rm -f /var/spool/cron/lastrun/cron.hourly  <- do not run every hour
15     8   * * *    root  rm -f /var/spool/cron/lastrun/cron.daily
0      8   * * wed  root  rm -f /var/spool/cron/lastrun/cron.weekly
30     8   1 * *    root  rm -f /var/spool/cron/lastrun/cron.monthly
*/10   *   * * *    root  test -x /usr/sbin/run-crons && /usr/sbin/run-crons

Restart cron daemon:

# /etc/init.d/vixie-cron restart

User Cron Configuration

Add user to 'cron' group

gpasswd -a username cron

Use the following commands

crontab -e           <- edit schedule for current user
crontab my-crontab   <- replace entire schedule for current user
crontab -l           <- list schedule
crontab -r           <- remove schedule for current user

crontab entry syntax

minute hour dayOfMonth month dayOfWeek command

example - at 5:00 run 'stuff'

0     5     *     *     *    stuff

Cron and Ruby

To use a custom RUBYLIB, include the variable in crontab.

RUBYLIB=/root/rubylib/
# m h  dom mon dow command
  0 12  *   *   *  ruby /path/to/script.rb

Output From Vixie-Cron

stdout and stderr from the scripts in cron.* goes in a mail to root

References

Personal tools