You are not logged in.
Pages: 1
I'm really new to bash and scripting in general, so bare with me.
The script I'm trying to make is supposed to take an initial time as a parameter and schedule the atd to run a command at that time, and every 5 minutes afterwards for the next hour. The really simple problem that I'm having trouble with is converting to the next hour after it hits 60 minutes. So say that the starting time I give is 1330. I want it to schedule a command to run every 5 minutes until 1430, but I don't know how to get it to translate 1360 to 1400, 1365 to 1405 and so on.
This is what I have so far with an echo statement being substituted for the actual scheduling:
#!/bin/bash
starttime=$1
i=1
while [ "$i" -lt "14" ]
do
echo "start time = $starttime"
starttime=$(( $starttime + 5 ))
i=$[$i+1]
done
As you'd guess, if you run it with "1330" as the parameter, it goes to 1390 instead of 1430. What's the best way to translate those numbers? This problem seems to be embarrassingly simple, but I'm having trouble with it.
Offline
Get two variables, one for the min and other to the hours. I think it is the easy way, so startime become in two arguments.
Offline
Here's a clue if you want to use one input:
$ date -d "+100minutes 14:30" +%H:%M
16:10
Offline
It seems you want to feed the time in %H%M format to some other program (atd?). Does this receiver program only support this format?
Either way, you can always calculate time in seconds/minutes, and then convert to/from hour_min format, e.g.
min2hhmm() { printf '%02d%02d\n' $(($1 / 60)) $(($1 % 60)); }
hhmm2min() { echo $((${1:0:2} * 60 + ${1:2:2})); }
delta=5
min2hhmm $(($(hhmm2min $1) + $delta))
$ ./t.sh 0359
0404
This silver ladybug at line 28...
Offline
Pages: 1