Linux: Add Jobs to Cron
This post will guide you how to add corb job in your current Linux operating system. How to use cron tool to run commands or your own scripts at a given date in Linux. We have talked that in the previous post about Linux crob, and it will run commands or your scripts at a specified date and time in current system.
The cron service will check the /etc/crontab config file and this file contain the cron job that you want to run. and you need to use the crontab command to create, delete, install or list the cron jobs in Linux system.
Create Your Own Cron jobs
If you want to create your own cron jobs, you need to use the crontab command to create your own crontab config file. issue the following command:
#crontab -e
Crontab Syntax
The syntax of the crontab command is as below:
# .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed
For example:
1 2 3 4 5 scott /test.sh
or
1 2 3 4 5 scott commmand
Linux Cron Examples
If you want to run a script named as /checkfio.sh at 14PM everyday in your system, just do the following steps:
#1 create your crontab entry, issue the following command.
#crontab -e
#2 add your crontab entry into your crontab file. just like below line:
0 14 * * * /checkfio.sh
#3 save and close your crontab file.
Then the cron service will check your crontab file, if the current system date and time is equal to the specified date and time, and then your script will be run automatically.
You can issue the following command to check if your cron job has been added into your crontab file.
#crontab -l
Outputs:
[root@osetc ~]# crontab -l 0 14 * * * /checkfio.sh