Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using bash and wondering how I can execute a command/script at a later specified time, with the accuracy of a second?

I read the man page for the at-command, but as far as I could understand it's only possible specify minutes (and not seconds). Right now I first use at and then sleep to get it to execute the right second. To demonstrate, if I would like to run my_script.sh at 22.21.05 I would do:

echo "sleep 5; my_script.sh" | at 22.21

But it would be much nicer to have a command with it built in. Something like at 22.21.05.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

I don't believe that this is possible. cron is only granular down to the minute and the at utility hooks into it to do it's work. I think you have the right solution--sleeping for x seconds before executing.

share|improve this answer
add comment

You could make your technique into a function:

atplus () { local sec=${1##*.} time=${1%.*}; shift; echo "sleep $sec; $@" | at $time; }

Try it out:

atplus 22.21.05 my_script.sh

You should be aware, however, that precision is not guaranteed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.