Linux - Schedule a cron task with Crontab
An experienced Linux sysadmin knows the importance of running the routine maintenance jobs in the background automatically.
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
MIN - Minute field 0 to 59
HOUR - Hour field 0 to 23
DOM -Day of Month 1-31
MON -Month field 1-12
DOW -Day Of Week 0-6
CMD - Command
Any command to be executed.
Scheduling a Job For a Specific Time
The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
30 08 10 06 * /home/ramesh/full-backup
List Crontab Entries
List or manage the task with crontab command with -l option for current user
crontab -l
Edit Crontab Entries
To edit crontab entry, use -e option as shown below. In the below example will open schedule jobs in VI editor. Make a necessary changes and quit pressing :wq keys which saves the setting automatically
crontab -e
Remove Crontab Entry
Caution: Crontab with -r parameter will remove complete scheduled jobs without confirmation from crontab. Use -i option before deleting user’s crontab
crontab -r
Prompt Before Deleting Crontab
crontab with -i option will prompt you confirmation from user before deleting user’s crontab.
crontab -i -r
crontab: really delete root's crontab?