Hi
I need to execute a function on set intervals, in seconds.
Came up with this:
Basically execution should happen if the current second mod the interval is equal to zero.Code:#!/bin/bash INTERVAL=2 while true; do SECOND=`date +"%S"` (($SECOND % $INTERVAL)) || echo "execute on second: $SECOND" sleep 1 done
Sample output:
execute on second: 00
execute on second: 02
execute on second: 04
execute on second: 06
./timer.sh: line 4: ((: 08: value too great for base (error token is "08")
execute on second: 08
./timer.sh: line 4: ((: 09: value too great for base (error token is "09")
execute on second: 09
execute on second: 10
execute on second: 12
execute on second: 14
execute on second: 16
execute on second: 18
execute on second: 20
execute on second: 22
execute on second: 24
Anybody knows what is happening there on second 8 and 9?
Tested on CentOs and OSX.

Reply With Quote
