x

CRONTAB command in Unix

PREV     NEXT

  •  In Unix, you have the capability to schedule the jobs/scripts to run at the specified time.
  • We can schedule jobs to run at the specified intervals like once a day or once a week or once a month or once in every hour/5 mins/ 10 mins/ 15 mins etc using crontab.

Each entry in a crontab file consists of six fields, specifying in the following order:

 

  • minute(s)    hour(s)    day(s)    month(s)    weekday(s)    command(s)
  • The above fields should be separated by spaces or tabs. The first 5 fields in above format should be in integer patterns and the 6th should be command to execute.

The below table will describe in detail.

Field / Value Description
minute / 0-59 The exact minute that the command should execute
hour / 0-23 The hour of the day that the command should execute
day / 1-31 The day of the month that the command should execute
month / 1-12 The month of the year that the command should execute
weekday / 0-6 The day of the week that the command should execute (Sunday = 0, Monday = 1, Tuesday = 2 and so on..)
command / Special Instruction The command information needed to execute. It should be either commands, executables (such as scripts), or combinations are acceptable.

Ex:


  • In the above example, the script or job “myScript.sh” will run for every 15 minutes once all day of week, month and year.

  • In the above example, the script “myScript.sh” in the bin directory will be executed on the 1st  and 15th of each month, as well as on every Monday.

  • In the above example, the script “myScript.sh” from the bin directory will be executed only on Mondays.
  • To create the crontab file in Unix, type crontab space filename.

Ex:

crontab filename or crontab -a filename

Crontab -l :-

To display the crontab file available in Unix system.


Crontab -e :-

  • To edit the crontab file available in the Unix.
  • It will create the crontab file if it does not exist in the system.

Crontab -r :-

To remove the crontab file from the system.

Crontab -v :-

To display the last time when the crontab file was edited.



Like it? Please Spread the word!