#!/bin/bash doPing() { DEST=$1 ping -c 1 $DEST } pingWait() { DEST=$1 TIME=$2 doPing $DEST & PID=$! sleep $TIME # Return false if the program hasn't terminated after the given time. if ps $PID &> /dev/null; then kill $PID &> /dev/null return 1 fi # If it returned, see if it was successful. wait $PID return $? } if [[ $# -ne 2 ]]; then echo " Usage: $0 " 1>&2 exit 1 fi # pingWait DEST TIME pingWait $1 $2