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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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

Your Answer


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.