Job Scheduling in LINUX


Cron is a time based job scheduler for Unix based OS.  Most of the Linux Distributions have it installed. Job scheduling is much more simple with cron. First of all, make sure that cron is installed.

rpm -qa crontabs

If output shows something then cron is installed. Otherwise we can install it.

yum install crontabs

Suppose we have to run a copy operation (for backup purpose) everyday at 12:01pm. The scheduling starts with the following command.

crontab -e

Generally the command opens a Schedule file in VI Editor. Then write the following script in that file & save that. If you aren’t familar with VI Editor then visit http://www.cs.colostate.edu/helpdocs/vi.html

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

  1. ._____________ minute (0 to 59)
  1. |  .___________ hour (0 to 23)
  1. |  |  ._________ day of month (1 to 31)
  1. |  |  |  ._______ month (1 to 12) OR (jan to dec)
  1. |  |  |  |  ._____ day of week (0 to 6) (Sunday=0 or 7)  OR
  1. |  |  |  |  |      sun,mon,tue,wed,thu,fri,sat
  1. |  |  |  |  |
  1. *  *  *  *  *  command to be executed

1 12 *  *  *  cp /file1 /file2

The script is self descriptive as the comments of the script explains the operation. Finally

service crond restart

Customize the script to schedule your own tasks. That’s all, Enjoy!!

Advertisements