The blog provides Network Security Tips, Tricks, How To/Procedures. Products and areas not limited to Firewalls, Security, Check Point, Cisco, Nokia IPSO, Crossbeam, SecurePlatform, SPLAT, IP Appliance, GAiA, Unix/Linux.

Linux/Unix - How To Setup Cron Job - Schedule Job

Cron is a software utility that allows to schedule job to run on specific time in Linux/Unix based operating system. Linux/Unix command or a shell script can be scheduled to run on specific time, either recurring or not. It's possible to schedule more that one job, each job can be scheduled to run on the same time or different. List of cron jobs are stored in a cron table, using 'crontab -e' command cron table can be edited, that is cron jobs can be added, deleted or modified.

In Linux/Unix based operating system, each user can setup a crontab.

Syntax:

crontab -e

┌───────────── min (0 - 59) 
│ ┌────────────── hour (0 - 23)
│ │ ┌─────────────── day of month (1 - 31)
│ │ │ ┌──────────────── month (1 - 12)
│ │ │ │ ┌───────────────── day of week (0 - 6) (0 to 6 are Sunday
│ │ │ │ │                   to Saturday, or use names; 
│ │ │ │ │                     7 is Sunday, the same as 0)
│ │ │ │ │
│ │ │ │ │
* * * * *  command to execute


Example:

In this example, output of 'time' command will be saved in /var/tmp/time.log file every 30 minutes.

[root@Linux]# crontab -e
30 * * * * clock > /var/tmp/time.log
~
~
~
~
# Comment: Start line with hash '#' to add comment.
#
Comment: After adding/deleting/editing job, hit 'Esc' key and type ':wq' to Write and Quit. Type ':q' to Quit without saving changes. Also ':wq!' & ':q!' can be used where exclamation suffix would force the command.
~
~
"/tmp/crontab.XXXXp423Fn" 1L, 39C 

:wq

crontab: installing new crontab
[root@linux]#



Linux/Unix - How To Setup Cron Job - Schedule Job Linux/Unix - How To Setup Cron Job - Schedule Job Reviewed by Admin on 13:26:00 Rating: 5