2

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this. in my script I need to check both time and string which is read from text file. if the current time is 6 am and string is "running" , the parent script should trigger. can you help how to check if the string is "running" via shell script.
hm, you write:also need to check the string from text file(status)... Do you want to write status in text file? Whats is status? Process status ? So, I got it as: 1. Check status your process, write status in text file, and if time at 6 am and if status is running, start parent script. Did I understand correctly?
yes, you are correct and I tried the same thing yesterday and it is running as expected. thanks for your support!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.