You can use cron
to run your script at specific times.
First create a script (say tc_script.sh
) to run those two commands as:
#!/bin/bash
/tomcat/bin/shutdown.sh
/tomcat/bin/startup.sh
Second, edit the crontab
file to run this script at midnight everyday. To do that type crontab -e
in you termainal which will open the crontab file
where you can enter commands to be executed at specific times.
In this file, add a new line as:
00 00 * * * /tomcat/bin/tc_script.sh
Syntax of crontab file is as follows:
minute hour day_of_month month day_of_week <command>
So the above line say, run the command in 00
minutes, 00
hours everyday every month (*
means any/every).
cron
also recognizes @daily
keyword, so you can also use that as it is shorter and more readable.
@daily /tomcat/bin/tc_script.sh
@daily
will make cron
run the script at midnight everyday.