Thread
:
Shell script to run command in time frame of day
View Single Post
ivyking
2011-08-21 , 20:24
Posts: 237 | Thanked: 274 times | Joined on Jul 2010
#
3
either use alarmed as stated above, or
make a script that basically contains a while loop, inside you put a sleep statement for example 120 seconds, and check hwclock for time, and using an if statement compare the time with what you want then execute what you would like to.
note that the time you add to sleep command is the time between successive executions of your script, don't make it too fast or it will kill your battery, 2-5 minutes interval is good imo.(sleep commands uses seconds as input)
also if your script executes a binary, you may want to store it's pid on execution, and next loop check if it's already running before executing again.
if you want to call your script to execute a given binary, like :
myscript.sh command1 command2
and want whatever you call the script with not to be executed unless a certain time is met, then there is no need for a while loop, just check the time, again using hwclock, then execute the first argument, second argument...etc.
do that by getting the argument, manipulating it into correct form then executing by placing the command between ``
you may need some text manipulation to get the output of hwclock to a format you can compare with a given string, similarly you may need to manipulate the arguments for your purposes, use sed, awk for that.
the above are general ideas, if you need help with the actual script, syntax just say, and give some info on how exactly you want it to function.
Last edited by ivyking; 2011-08-21 at
20:47
.
Quote & Reply
|
The Following User Says Thank You to ivyking For This Useful Post:
Estel
ivyking
View Public Profile
Send a private message to ivyking
Find all posts by ivyking