I have this script:
FINISH=0;
trap 'FINISH=1' SIGINT
INTERVAL=100;
while true
do
START=`date +%s`;
php-cgi -f process.php;
STOP=`date +%s`;
ELAPSED=$(($STOP-$START));
SLEEP=$(($INTERVAL-$ELAPSED));
if [ $SLEEP -gt 0 ]
then
echo "sleeping for $SLEEP seconds";
sleep $SLEEP;
fi
if [ $FINISH -eq 1 ]
then
echo "exit";
break;
fi
done
But it doesnt work as I would like – I want it to just set FINISH=1 but it kills currently executed command (php-cgi or sleep) – how to avoid this? Actually I don’t want it to kill php-cgi…
This might work for you.