Reputation: 29
for example: current time : 8:30 PM i need to run for next 2 hrs for 8.30, 8.31.... so on for 2 hrs. I am expecting this run should print 120 output results. please help.
Need this in shell script.
Upvotes: 0
Views: 28
Reputation: 4455
Here's a quick and dirty answer, if you don't mind hard coding 120 minutes in the for
expression:
for min in {1..120}
do
command & # launch in background to minimize drift
sleep 60
done
Alternatively, modify crontab entry (avoid all drift considerations):
crontab -l > /tmp/oldcron.$$
crontab << EOF
$(crontab -l )
*/2 * * * * command # run command every 2 minutes forever
EOF
sleep $(( 2 * 60 * 60 )) # sleep 2 hours
crontab < /tmp/oldcron.$$
The above probably suffers by an off-by-1 type of error. You may need to add 59 seconds to the sleep.
Upvotes: 1
Reputation:
#!/usr/bin/env bash
count=0
max=120 # 2 * 60 minutes
while [ true ]; do
((count++))
sleep 60
# terminal -e command
if (( $count > $max )); then
break
fi
done
Upvotes: 0