Linux命令:AUTO PING
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux命令:AUTO PING相关的知识,希望对你有一定的参考价值。
分别使用while,until和for(两种形式)循环实现。
要求:通过ping命令测试主机是否在线,
如果在线,就显示"ip is up.",其中的IP要换为真正的IP地址,且以绿色显示;
如果不在线,就显示"ip is down.",其中的IP要换为真正的IP地址,且以红色显示;
#!/bin/bash
#
for I in {200..201}; do
ping -c 1 -W 1 10.109.131.$I &> /dev/null
[ $? -eq 0 ] && echo -e "\033[36m110.109.131.$I is up\033[0m" ||echo -e "\033[35m110.109.131.$I is down\033[0m"
done
declare J=215
while [ $J -lt 217 ] ;do
ping -c 1 -W 1 10.109.131.$J &> /dev/null
PP=$?
[ $PP -eq 0 ] && echo "110.109.131.$J is up" ||echo "110.109.131.$J is down"
let J++
done
declare K=220
until [ $K -gt 222 ] ;do
ping -c 1 -W 1 110.109.132.$K &> /dev/null
P3=$?
[ $P3 -eq 0 ] && echo -e "\033[36m110.109.132.$K is up\033[0m" ||echo -e "\033[35m110.109.132.$K is down\033[0m"
let K++
done
[[email protected] ~]# ./ping.sh
110.109.131.200 is up
110.109.131.201 is up
110.109.131.215 is down
110.109.131.216 is down
110.109.132.220 is up
110.109.132.221 is down
110.109.132.222 is up
以上是关于Linux命令:AUTO PING的主要内容,如果未能解决你的问题,请参考以下文章