Dipesh Majumdar

Blog and Paintings

Run a script in crontab

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 ( residing in location /xyz/pqr every 30 minutes. You need to enter below entry in crontab -e
*/30 * * * * /xyz/pqr/

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/

suppose you want to run a script at 14:49 pm everyday - you can configure this way

41  14 * * *  /u01/appl/scripts/ 


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

sometimes cron job will fail to trigger from a particular user- 

always do a tail for the logs - example below. i have once found that the home directory wasn't present for user1 and so the error in below log was coming as

(CRON) ERROR chdir failed (/home/user1): No such file or directory

after the user1 home directory was created the issue was solved



Go Back