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.

3 Answers 3


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.


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.


Actually at may support seconds

I think this is not always well supported (depending on the particular implementation), but in principle at may support seconds.

From the man page:

-t time run the job at time, given in the format [[CC]YY]MMDDhhmm[.ss]

Look at the [.ss] at the end.

This means that, using the -t option, you can type something like

echo "yourscript.sh" | sudo at -t 04281549.45

i.e. the command should be executed at 15:49:45 (45 seconds).
(on April the 28th)

When I tried it, as expected the output from at was:

job 38 at Wed Apr 28 15:49:45 2021

Note: when I tried it, it was still late by some seconds, but it still was executed not before 15:49:45, meaning that the specified seconds are not ignored by at internally, they are actually considered. Therefore, specifying seconds can still be useful when you want to say something like "delay this command to run it not earlier than 15:49:45".

  • what version of at? I am running 3.1.23 on two different boxes and neither works the way you show even though the man page shows it just like yours.
    – user_ABCD
    Commented Nov 11, 2021 at 18:54
  • What do you mean when you say it does not work? What is the output of the command? Do seconds appear in that output? Commented Nov 11, 2021 at 19:18
  • I use your exact command and get no second precision. job 18 at Wed Apr 28 15:49:00 2021
    – user_ABCD
    Commented Nov 11, 2021 at 19:47
  • I have just tried with at in MacOS Sierra and it has second precision. I cannot tell which version it is, apparently writing -v or --version does not work... Commented Nov 11, 2021 at 19:54
  • at -V. I am 3.1.23 on Ubuntu 20.04.
    – user_ABCD
    Commented Nov 11, 2021 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .