Subhasish Dash Subhasish Dash - 3 months ago 11
Linux Question

How to write a script file for centos to restart tomcat every day at midnight

I am in the need of restarting tomcat everyday @midnight.
I have no idea in writing scripts in centos .

Basically looking for a script that will execute following commands every 24 hr for the files located in /tomcat/bin/ :

  • ./

  • ./


If tomcat is installed as a service, you should be able to use a cronjob call those scripts at midnight every night. There's a tutorial on how to use crontab here:

This answer has an example for midnight crontab: cron that will run a ruby script every day at midnight

If the service doesn't work, you could use

    00 00 * * * bash -c '/tomcat/bin/ && /tomcat/bin/'

I don't have somewhere to try it, so that's the best I can give you.