Menu

Dipesh Majumdar

Blog and Paintings

Run a script in crontab

August 27, 2014

Why not?

Why the hell bother to do something manually - particularly some periodic task?

Rather you can provide all information in crontab and it will run your script periodically. There is plenty of information about crontab in google which you can easily find out. I am providing a simple example below - 

* * * * *

5 stars

1.  (0-59) minutes

2. (0-23) hours

3. (1-31) days

4. (1 - 12) months

5. (0-6)   that means 1 is monday, 2 is tue, 3 is wed, 4 is thu, 5 is fri and 6 is saturday

 

Suppose you need to run a script (script1.sh) residing in location /xyz/pqr every 30 minutes. You need to enter below entry in crontab -e
*/30 * * * * /xyz/pqr/script1.sh

Suppose you need to run the same script every day at 12:01 am... you need to enter below entry in crontab -e
01  00 * * *  /u01/appl/scripts/script1.sh

Now you can find all the jobs configured in crontab by this command -
crontab -l

Go Back

Cron is best suited for servers where they are shutdown seldom. But for laptops and desktops anacron can be used which will run the task even if the system is shut down at the mentioned time. The delayed task will run after the laptop is turned on.



Comment