Hi Everybody,
I want to run a script at every 5 seconds. I know how to run it every 5 minutes, is there any possibility to run a script at 5 seconds interval.
Regards,
Mastan
Hi Everybody,
I want to run a script at every 5 seconds. I know how to run it every 5 minutes, is there any possibility to run a script at 5 seconds interval.
Regards,
Mastan
Possibly better to wrap your script as a loop, e.g.
#!/bin/ksh
lastsec=-1 # Set to an invalid second count to ensure an immediate start.
while true
do
currsec=`date +%S`
((testsec=$currsec/5))
((testsec=$testsec*5))
if [ $testsec -eq $currsec -a $testsec -ne $lastsec ]
then
run-your-code-here
else
sleep 1
fi
lastsec=$currsec
done
Of course, this never ends unless you put an exit
in the code somewhere. You could consider testing for the minute to have passed and end, then schedule it with cron every minute, that way if it ever crashed out, it would be started again.
Not a great way, but it's an option. One wonders why you need to run it every five seconds. Can you enlighten us?
Anyway, I hope that this helps or gives you useful thoughts.
Robin
Liverpool/Blackburn
UK
Or:
watch -nX your_script
Where X is any number of seconds.
or you could just let the script sleep every 5 seconds ... start it from cron every start of the hour ... script sample below wil exit if $lockfile exists ... removing lockfile will kill running script ...
#! /bin/ksh
lockfile=/tmp/lockfile
repeatJob(){
echo "boo"
echo "duh\n"
if [ ! -f $lockfile ]
then
break
else
sleep 5
repeatJob
fi
}
if [ ! -f $lockfile ]
then
touch $lockfile
repeatJob
else
echo "$lockfile exists. Exiting."
exit 1
fi
exit 0