Active Topics

 


Reply
Thread Tools
Posts: 669 | Thanked: 433 times | Joined on May 2010
#1
I want to make a script that executes a command only if the time of day is between 16:00 and 18:00. anyone knows how i can do that?

the script will be run by an event from the phone, but the command itself must not run if the time of day is not between this time frame.

Thanks.
 
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#2
You have a program called Alarmed that could do that.. just point it to what to run and when. The script must check if the event is valid..
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums
 

The Following 2 Users Say Thank You to AlMehdi For This Useful Post:
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.
 

The Following User Says Thank You to ivyking For This Useful Post:
Posts: 669 | Thanked: 433 times | Joined on May 2010
#4
alarmd is not an option - the trigger for this script is dbus event - i do not want it to run in certain hour (if i did - i would know what time it is running).

I will definitely need help in making such a command in shell script (format the strings of course) since i am very weak at this:
the .sh script will be something like this is pseudo code:

if [ time is between 16:00 to 18:00 ]; then
[run the command]
fi

Thanks!
 
Posts: 47 | Thanked: 31 times | Joined on Jul 2010
#5
Originally Posted by impeham View Post
alarmd is not an option - the trigger for this script is dbus event - i do not want it to run in certain hour (if i did - i would know what time it is running).

I will definitely need help in making such a command in shell script (format the strings of course) since i am very weak at this:
the .sh script will be something like this is pseudo code:

if [ time is between 16:00 to 18:00 ]; then
[run the command]
fi

Thanks!
Code:
hr=`date +%H`
if test $hr -ge 16 -a $hr -lt 18
then
# do something here
fi
 

The Following 2 Users Say Thank You to ZedThou For This Useful Post:
erendorn's Avatar
Posts: 738 | Thanked: 983 times | Joined on Apr 2010 @ London
#6
Also you can wait two/three months until I finish my project
I'm writing a tool that determine system state based on files, dbus, time and other stuff, and launches actions (scripts, commands, dbus) when conditions on theses states are met (and or upon event).

but progress are slooow, sorry
 

The Following User Says Thank You to erendorn For This Useful Post:
Posts: 669 | Thanked: 433 times | Joined on May 2010
#7
Originally Posted by ZedThou View Post
Code:
hr=`date +%H`
if test $hr -ge 16 -a $hr -lt 18
then
# do something here
fi
Thanks - works great, but how can i add support for an exact hour with minutes - something like between 16:30 - 18:30?

Is there a place where it is explained how to manipulate this data?
 
Posts: 10 | Thanked: 29 times | Joined on Jun 2010 @ Germany
#8
Originally Posted by impeham View Post
Thanks - works great, but how can i add support for an exact hour with minutes - something like between 16:30 - 18:30?

Is there a place where it is explained how to manipulate this data?
Code:
hr=`date +%H%M`
You'll have to change the if condition to
Code:
if test $hr -ge 1630 -a $hr -lt 1830
If you have the man pages installed (see here) you can use man date to get an explanation. date --help would be another option, but on maemo this is extremely short. The man pages can be referenced online on various sites throughout the net, e.g. here.
 

The Following User Says Thank You to Obsidian For This Useful Post:
Posts: 669 | Thanked: 433 times | Joined on May 2010
#9
Thanks i finally managed to make it work right - even if day spans.
 
Reply


 
Forum Jump


All times are GMT. The time now is 13:47.