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:
SHELL=/bin/bash */29 7-23 * * * [ -n "$(pidof unison)" ] || (partner=188.8.131.52; ping -A -c5 $partner 6 7 |grep -w "ttl" || partner=184.108.40.206; time nice unison-sync $partner &> /tmp/sync.master.dev.log ) which ping /usr/bin/ping
This basically wants 220.127.116.11 to be the 1st choice sync host preference, however if it doesn't ping back at the moment then use 18.104.22.168 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=22.214.171.124; ping -A -c5 $partner 6 7 |grep -w "ttl" || partner=126.96.36.199; 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.