Configuring Cron Jobs

crontab commands

crontab -l  : To display the existing cron jobs created. Before creating cron job, we can use this command to check whether it is already created or not

crontab - r :  Remove user's cron jobs. All cron jobs will be removed.

crontab -e : Edit user's cron job, you can create a new cron job using this command. This command will open the default editor of your system, for me it's vi, if you prefer other editors such as vim. You can use export EDITOR=vim command.

crontab -u : Specify the user of the cron job

now we start to create a new cron job using crontab -e, this will open an editor, you can type the cron job into the editor. The syntax for the cron job is

* * * * * command to be executed

- - - - -




 * | | | - Day of week (0 - 7) (Sunday=0 or 7)


 * | | --- Month (1 - 12)


 * | - Day of month (1 - 31)


 * --- Hour (0 - 23)

- Minute (0 - 59)

The first five fields specify the time of the scheduled running job, the * means that for each cycle of the time field (For example, the * on hour means each hour, the * on day means each day, if * appears on  both hour and day field, it means every hour of every day). If we want to specify a particular time, we should put a number on relative time field. For example, if we want to run a cron job at 7:30 am every day, we should specify the cron job as

30 7 * * * command to be executed

example:

* /5 * * * * grant_priv_script.sh

45 23 * * * database_backup.sh

In case of the necessary to test the script by manually running the script manually the follow the steps give here.