Craig Sanders <[email protected]> wrote: >On Thu, Dec 12, 2013 at 10:33:32PM +1100, Allan Duncan wrote: >> I have a rc.local script that runs fine in csh, but I'd like to >change >> it to sh, but I've had no success at it. >> >> #! /usr/bin/tcsh >> if `ping -w 1 -c 1 -n 192.168.1.3 | grep -o "1 packets"` == "1 >packets" >> mount /nfs/bulk2 > >the simplest conversion to sh (with some fixes*) would be something >like: > >#!/bin/sh >if $(ping -w 1 -c 1 -n 192.168.1.3 | grep -q "1 packets") ; then > mount /nfs/bulk2 >fi
You shouldn't have the $() here at all. They're unnecessary and cause confusion. Remove them. Further, don't bother checking ping's output with grep's return code. Check ping's return code instead: If ping -w1 -c1 -n 192.168.3.1 >/dev/null 2&>1; then > >or as a one-liner: > >#!/bin/sh >ping -w 1 -c 1 -n 192.168.1.3 | grep -q "1 packets" && mount /nfs/bulk2 Again, grep unnecessary. -- Sent from my Android device with K-9 Mail. Please excuse my brevity. _______________________________________________ luv-main mailing list [email protected] http://lists.luv.asn.au/listinfo/luv-main
