What is the most convenient way of setting a crontab command to run every 59th second, other than running a sleep 59 in the beginning of my script?

If there are no other suggestions, will executing sleep 59 delay all my other cron entries scheduled for execution wait until the sleeping one completes?

Update Why do I need it at all? I've written a small script to find out who has logged on the system during the last minute, it looks like this:

who | grep `date +%R` | awk '{ print $1 " joins us." }' | write $USER

In order for it to work and not to get matters complicated, I need it to run in the end of the minute.


This has a date command that looks at the previous minute:

who | grep `date -d "now -1 min" +%R` | awk '{ print $1 " joins us." }' | write $USER

Then you could run it on the minute with cron:

* * * * * /some/dir/scriptname

You could even do this:

who | grep `date -d "now -60 sec" +%R` | awk '{ print $1 " joins us." }' | write $USER

Edit: Here's a freebie:

awk 'FNR > 2 {printf ",\n"} {printf "%s", name; name = $0; next} END {conj = " and\n"; if (FNR == 1) {singular = "s"; conj = ""}; printf "%s%s join%s us\n", conj, name, singular}'

Output with commas, "and" and plural verb agreement and removal of repeated phrase (you can replace the newlines (except for the last one) with spaces if you want it all on one line):

allen joins us


bill and
chris join us


ellen and
felicity join us


The best you can do using cron is run it every minute:

# minute hour dom mon dow
* * * * * /path/to/command
  • 1
    That doesn't answer my question, sorry. – dpq Oct 1 '09 at 16:16
  • 8
    Yes it does, your question was how to run a crontab every 59th second. MikeyB correctly answered that you can't. – Scott Lundberg Oct 1 '09 at 16:20
  • I stand corrected. – dpq Oct 1 '09 at 17:10

sleep 59 wouldn't delay other tasks.

But it smells like danger. If you need that level of granularity then I predict you will come unstuck.

If you explain the reason for your requirements you might find that someone is able to offer a better cure.


cron is just not that accurate. If you need that level of precision you should consider writing a daemon.

Have you considered using tail -f on the auth.log and just watching for logins constantly?


You'd be better off adding the script to all users .login file, or .bashrc, or similar.

1) It'd only run when someone logged in, so more efficient. 2) it would run instantly when someone logged in, so no delay.

  • I'm not root on that particular machine I want to install this thing on. – dpq Oct 1 '09 at 16:54

I'll just mention that zsh has a watch builtin that does just this. (Though, you must be using zsh, and using your shell, to see it: it won't pop up in other terminals.)

In brief, add this to your .zshrc:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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