shell简单ping函数

#!/bin/bash
pingserver=192.168.1.11

pingcmd()
{
ping -w 1 -c 1 $pingserver >/dev/null
result=`ping -w 1 -c 1 $pingserver|grep -q "ttl" && echo 0 ||echo 1`
return $result
}

pingcmd
ret=$?
if [ $ret -eq 1 ]
then printf "$pingserver is down"
fi

posted @ 2017-04-20 11:53  JonyQ  阅读(984)  评论(0编辑  收藏  举报