1

I want to schedule a shell script in crontab that runs whenever server restarts. It should also run when someone starts the server after it stops abruptly or crashes.

How to do so in crontab? Any suggestions would be of great help.

  • If you want to start it as a startup program, you can configure it in /etc/init.d/. Or do you only need it as a crontab? – rahul Mar 10 '15 at 5:20
4

Can you clarify what you are asking ? But to have cron run at restart you could use @reboot.

man 5 crontab

These special time specification "nicknames" are supported, which replace the 5 initial  time  and  date
       fields, and are prefixed by the ’@’ character:
       @reboot    :    Run once after reboot.
       @yearly    :    Run once a year, ie.  "0 0 1 1 *".
       @annually  :    Run once a year, ie.  "0 0 1 1 *".
       @monthly   :    Run once a month, ie. "0 0 1 * *".
       @weekly    :    Run once a week, ie.  "0 0 * * 0".
       @daily     :    Run once a day, ie.   "0 0 * * *".
       @hourly    :    Run once an hour, ie. "0 * * * *".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.