Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab Intro

INSTALLATION

Crontab Intro

by  Faroon  Posted    (Edited  )
This is the built-in automation tool for users of OpenBSD to set up task scheduling. Each user can have a separate crontab that holds several cronjobs to be executed periodically by a cron daemon. Synopsis:

$ crontab [-u (for user)] [-e (edit) | -l (list) | -r (remove)]

Synopsis of a command line in the contab (a cronjob):

Minute û Hour û Day of month û Month û Day of week /path/to/command /path/to/file

Minute: 0 û 59
Hour: 0 û 23
Day of month: 1 û 31
Month: 1 û 12
Day of week: 0 û 6, 0 = Sunday

Note: * = any value

User capacityÆs cronjobs:

# Refresh database tables everyday at 2:15am
15 2 * * * /usr/bin/perl /path/to/scripts/database_refresh.pl

# Backup table mytable and every Saturday 9:30am
30 9 * * 6 /usr/bin/perl /path/to/scripts/backup.pl

To edit a cronjob, do:
$crontab -l > temp.txt --> write current cronjob to file
$pico temp.txt (or use nano, of vi) --> make changes
$crontab temp.txt --> install back the job

Alternate way:
$export EDITOR=/path/to/pico (or nano, vi is default)
$crontab -e -->edit and save new jobs

Important: Cron has a different set of environmental variable settings from that of the user's. For example, the user's $PATH setting might have /sbin:/usr/sbin:/usr/local/sbin, but cron's $PATH might not. Sometimes extra environmental settings are required for a job to run inside cron. To make these setting, simply edit the cron, and add the neccessary settings on top of file (ex. add PATH=$PATH:/sbin:/usr/sbin)

Note: should a cronjob produce any error message, this message will be mailed to the owner of that cronjob. Simply type æmailÆ to open the email folder and view the cron daemon mail.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top