I am trying to create one wrapper script to trigger the parent script at 6AM only. But it is not properly working. It always showing Do Nothing and else part is looping without exit. Can any one help?
I want to check if the time is 6 AM and also need to check the string from text file(status). if both conditions are satisfied my parent script should execute via this wrapper script.
Below is the script
path= $(cat /home/avj/)
mode= $(cat /home/avj/status)
checktime=”060000″
echo $checktime
echo $currentTime
while true
do
currentTime=date +"%H%M%S"
if [[ $currentTime -eq $checktime && $status == running ]];
then
sh &path/parent.sh
else
echo Do Nothing
fi
done
Advertisement
Answer
Usually on Linux, you use crontab for this kind of scduled tasks. But you have to specify the time when you “set up the timer” – so if you want it to be configured in the file itself, you will have to create some mechanism for this.
For example, you can add crontab
30 1 * * 5 /path/to/script/script.sh
Will execute the script every Friday at 1: 30 (AM) here:
30 is minutes
1 is an hour
the next 2 * are the day of month and month (in that order), and the 5th is the day of the week