A host-ping test that always works correctly from the interactive bash command line in Cygwin, is behaving incorrectly in its own crontab--always selecting the second host--and I can't figure out why:


*/29 7-23 * * *  [ -n "$(pidof unison)" ]  || (partner=; ping -A -c5 $partner 6 7 |grep -w "ttl" || partner=; time nice unison-sync  $partner &> /tmp/sync.master.dev.log )
 which ping

This basically wants to be the 1st choice sync host preference, however if it doesn't ping back at the moment then use instead for this round. If unison is not already running, that is.

Yet running from the command-line always works as expected, echoing the first IP address if available, else the second:

partner=; ping -A -c5 $partner 6 7 |grep -w "ttl" || partner=; echo  $partner

In Ubuntu this works both in crontab and cli.

Is there a better way I can accomplish this, that is both compact and still portable on both my OSes (Linux Ubuntu 11.10 and Cygwin under Windows7,32bit)?

Even better, I'd like to generalize my host-checking to more that two, but still code it into a concise crontab line:

Use A if reachable, else use B if reachable, else use C if reachable, ... else just use Z.

  • Note that in Linux the test could be collapsed to ping -A -c5 $partner || partner=nnn however I needed to add the 6 7 and |grep ... for Cygwin compatibility.
    – Marcos
    Feb 28, 2012 at 13:24
  • Any reason you're not putting that thing in a script, and calling the script from cron? Might fix your problem.
    – Mat
    Feb 28, 2012 at 13:36

2 Answers 2


In Cygwin's crontab gave it the full path /usr/bin/ping and it works. Silly I didn't consider that earlier--in the shell it already showed precedence over Windows' version of ping and I left it at that long ago.

Guess I have to put up with the quirks of that cron environment (like so much else in cygwin) unable to keep things fully identical with my native Linux hosts. In Ubuntu it's /bin/ping btw.

Considering andLinux in place of Cygwin in the future.

If somebody still showed me a compacted multiple-hosts failover list A..B..etc..Z version would much appreciate it.


Have you considered using Balance? Their site indicates that it works on Cygwin. You could unison-sync to localhost:5555 and then load-balance port 5555 to multiple hosts with RR or failover.

You must log in to answer this question.

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