Thursday, November 1, 2018

Crontab setup and steps

Hello guys, 
Here is my one more blog about the crontab scheduler which is most important future to know to every DBA.

Crontab allows a task to be run automatically in background at mentioned date/time.
Crontab has 5 variable inputs which will allow user to schedule the script to execute on the time/date/day according to the user input.

Sample:
1 2 3 4 5 /home/vinaychandra/remove_file.sh

I have a shell file which will remove the some file, lets see how can i schedule it in different events. First most we need to know which parameter is used for what.

1 - Minute (from 0 to 59)
2 - Hour (from 0 to 23)
3 - Date of the month ( from 1 to 31)
4 - Month ( from 1 to 12)
5 - Day of week (from 0 to 7, here 0 and 7 are Sunday)

And to list the existing crontab or edit it, use following

$crontab -l  --> To list
$crontab -e --> To edit

Now, lets see the events:

Please find the below examples for references:

1. Suppose we want to execute any scripts every minute then we can use below commands:

* * * * * /home/vinaychandra/remove_file.sh

Here, * asterisk or start means every. So, this above command will run for every minute, every hour, and every date of month, every month and every day of week.

2. Example for execute on Friday at 7 AM, each date and every month.

0 7 * * 5 /home/vinaychandra/remove_file.sh

3. Suppose, we want to execute our scripts only on Friday and Saturday at 5 AM.

0 5 * * 5-6 /home/vinaychandra/remove_file.sh

4. Suppose, we want to execute at every 10 min.

0,10,20,30,40,50 * * * * /home/vinaychandra/remove_file.sh

That's it.





No comments:

Post a Comment