Resource icon

Scheduling cron job under Linux or UNIX

Adding Jobs To cron Under Linux or UNIX:

Using cron the Linux and UNIX users can run their scripts and commands at the specified time and date. Scripts can also be scheduled. Corn is the mostly preferred tool for running system admin jobs and it will always executed in the background. It usually checks the /etc/crontab file, /var/spool/cron/ directory and /etc/cron.*/ directory. Crontab command is to install, create, edit, uninstall or list cron jobs that belongs to Vixie Cron. Every use have a corn file and they can edit the files in /var/spool/cron/crontabs.

Creating or Editing the Corn Jobs:

$ crontab –e
The above command is used to create or edit corn jobs in UNIX or Linux. Cron don’t want to be restarted while modifying the corn file.

Cron Configuration File Types:

The UNIX / Linux system crontab is usually used by critical jobs and services of the system that is required by privileges. The user crontab allows the user to install their own corn jobs with the crontab command.

Crontab Syntax:

1 2 3 4 5 /path/to/command arg1 arg2

1 2 3 4 5 /root/

Here one represents the minutes, 2 represents the hours, 3 specifies the days, 4 represents the months and 5 specifies the day of the week. /path/to/command indicates the name of the command and scripts that needs scheduling.

1 2 3 4 5 USERNAME /path/to/command arg1 arg2
The above command is used for the system jobs.


# crontab –e

0 3 * * * /root/
The cron job is installed in the first command and next command is used to run the /root/ script for every day at 3 A.M. the file is saved and closed after the execution.


Operators are used for defining values in the field.

The asterisk operator (*) indicates all the values for values of the field. For instance, the * in month field indicates every month in the year.

The comma operator (,) indicates the list of values. 1, 5, 10, 15 is an example.

The dash operator (-) specifies the range of the values. For instance 10-15 indicates the values from 10 to 15 i.e 10, 11, 12, 13, 15.

The separator operator (/) indicates the values in steps.

Disabling email outputs:

The output of the script or command will be mailed to the local email account by default. To stop sending the email >/dev/null 2>&1 has to be appended to crontab.


0 3 * * * /root/ >/dev/null 2>&1
For defining MAILTO variable the above commands are used. Here output is mailed to

Cron jobs lists:

# crontab -l
# crontab -u username –l
Below command is used to remove the crontab jobs

# Delete the current cron jobs #

crontab –r
## Delete job for specific user. Must be run as root user ##

crontab -r -u username
/etc/crontab is the crontab file of the system. It is used only by the root user for the configurations of system jobs.

How to use my own cron jobs or script?

The below script use to check the specific port is down or not or if it is then you will get the email notification about it. This script put in /var/spool then you have to call the script through below expression, this expression will execute the cron in every minute.

*/10 * * * * sh /var/spool/
#!/usr/bin/env bash
if [ "$?" -ne 0 ]; then
  echo "" | mail -s "Server Down"
  exit 1
  exit 0
Bhawani Singh
First release
Last update
0.00 star(s) 0 ratings

More resources from Bhawani Singh