Setting up a cron job in UNIX-type operating systems

  • Article ID: 12176
  • Rating:
  • 58 customers rated this article 4.6 out of 6
  • Updated: 30 Jul 2009

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.

  1. Open a root shell and type the following:
    crontab -u root -e
    to open a VI style editor.
  2. Press 'i' to insert text.
  3. 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/

    You can replace a field value with "*". So:
    0 10 * * * /path/
    is the same as
    0 10 1-31 1-12 0-7 /path/
    The script concerned would run at 10 each morning.

    For example, to run a scan with Sophos Anti-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.
  4. When you have created the crontab, press 'Escape' to leave insert mode.
  5. 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.

Rate this article

Very poor Excellent