Setting up a cron job in UNIX-type operating systems
Cron jobs can be used for setting up scheduled scans in UNIX-type operating systems, e.g. UNIX, Linux, FreeBSD and Darwin (Mac OS X).
What to do
Note: The syntax may differ, depending on which version of cron is present on your computer.
- Open a root shell and type the following:
crontab -u root -eto open a VI style editor. - Press '
i' to insert text. - The crontab comprises five entries indicating the schedule time, and also the name and path of the program to be run. Use a space or a tab between each entry:
minute(0-59) hour(0-23) day_of_month(1-31) month(1-12) day_of_week(0-7) /path/script.sh
You can replace a field value with "*". So:0 10 * * * /path/script.sh
is the same as0 10 1-31 1-12 0-7 /path/script.sh
The script concerned would run at 10 each morning.
For example, to run a scan with SophosAnti-Virus which will delete infected files at 8 o'clock each night in Linux (in Darwin the path to sweep is not necessary), use:
0 20 * * * /usr/local/bin/sweep /directory/subdirectory -remove
Names can be used (e.g. March) for month and day of week. In day of week, Sunday can be 0 or 7.
- When you have created the crontab, press 'Escape' to leave insert mode.
- Type '
ZZ' (upper case 'z' twice). A message similar to the following should be displayed:/crontab.zUcAAFwPVp: 1 lines, 24 characters
crontab: installing new crontab
The crontab has now been set up. Cron will automatically send an email to root to confirm that the scan has run.
For more information on cron and crontab, read the relevant manual pages. For example, type:
man crontab
to see the crontab manpage.
If you need more information or guidance, then please contact technical support.
- Article ID: 12176
- Created: 9 Nov 2004
- Last updated: 8 Oct 2008
