Easiest way is to put cron job to start it minute earlier and then add timing by your own.
You can also use at
. At least man page of at
says that you can use rather exact timing, including seconds. You can test this by adding at
job that records time, for example shell script running
date > ~/at_test
If you go with cron route, date +%s
is your friend.
For example
#!/bin/bash
target_time=1298301898
let wait_time=target_time-`date +%s`
if [ $wait_time -gt 0 ]; then
sleep wait_time
fi
# Execute your code
With this approach your next problem is to figure out how to determine target_time. If you always know that you want to start it in the next minute, you can use
sleep 2 # Avoid running on xx:59, if cron starts immediately.
let wait_time=60-`date +%M`
sleep wait_time
to wait until minute changes.
date
's nanosecond timer... Using seconds can at best give you an average of +/- 0.5 of a second... But it's unlikely that it matters... I've just put it together as an exercise... – Peter.O Feb 22 '11 at 00:01