[root@192 media]# ./targethost.sh
connect: 网络不可达
targethost is down
[root@192 media]# ./targethost.sh
PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.
64 bytes from 192.168.1.4: icmp_seq=1 ttl=64 time=0.355 ms
64 bytes from 192.168.1.4: icmp_seq=2 ttl=64 time=0.426 ms
64 bytes from 192.168.1.4: icmp_seq=3 ttl=64 time=0.616 ms
64 bytes from 192.168.1.4: icmp_seq=4 ttl=64 time=0.746 ms
^C
--- 192.168.1.4 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 0.355/0.535/0.746/0.156 ms
targethost is up
[root@192 media]# cat targethost.sh
#!/bin/bash
ipaddr=192.168.1.4
ping -c 4 $ipaddr
if [ $? = 0 ]
then
echo "targethost is up"
else
echo "targethost is down"
fi
shell-测试服务器是否宕机
猜你喜欢
转载自blog.csdn.net/weixin_45110196/article/details/104543381
今日推荐
周排行