crontab to schedule task excuted regularly

http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/comment-page-1/

Linux Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis

Examples:
1, This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
30 08 10 06 * /home/ramesh/full-backup

2,This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day
00 11,16 * * * /home/ramesh/bin/incremental-backup

3,This example checks the status of the database everyday (including weekends) during the working hours 9 a.m – 6 p.m
00 09-18 * * * /home/ramesh/bin/check-db-status
Schedule a Background Cron Job For Every 10 Minutes.
*/10 * * * * /home/ramesh/check-disk-space
4, This will execute the system annual maintenance using annual-maintenance shell script at 00:00 on Jan 1st for every year.
@yearly /home/ramesh/red-hat/bin/annual-maintenance
5, Schedule a Cron Job Beginning of Every Month using @monthly
@monthly /home/ramesh/suse/bin/tape-backup

To view your crontab entries type crontab -l from your unix account as shown below
-bash-4.1$ crontab -l
no crontab for username
To view crontab entries of other Linux users, login to root and use -u {username} -l
To edit a crontab entries, use crontab -e as shown below. By default this will edit the current logged-in users crontab.
-bash-4.1$ crontab -e
[Note: This will open the crontab file in Vim editor for editing. Please note cron created a temporary /tmp/crontab.XX… ]
When you save the above temporary file with :wq, it will save the crontab and display the following message indicating the crontab is successfully modified.

Installing Crontab From a Cron File

Instead of directly editing the crontab file, you can also add all the entries to a cron-file first. Once you have all thoese entries in the file, you can upload or install them to the cron as shown below.

ramesh@dev-db$ crontab -l
no crontab for ramesh

$ cat cron-file.txt
@yearly /home/ramesh/annual-maintenance
*/10 * * * * /home/ramesh/check-disk-space

ramesh@dev-db$ crontab cron-file.txt

ramesh@dev-db$ crontab -l
@yearly /home/ramesh/annual-maintenance
*/10 * * * * /home/ramesh/check-disk-space
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s