#!/bin/bash #监控主机存活频率 echo -n -e " 请输入查询的ip是否在线: " read IP for ((;;)); do ping $IP -c 2 &>/dev/null if [ $? -eq 0 ];then echo -e "33[32m $IP is online 33[0m" else echo -e "33[31m $IP is offline 33[0m" fi sleep 5 done
#!/bin/bash #监控主机是否存活 read -p "请输入需要查询的主机ip: " IP while true ; do ping $IP -c 1 &>/dev/null if [ $? -eq 0 ]; then echo -e "33[32m $IP is online 33[0m" else echo -e "33[31m $IP is offline 33[0m" fi sleep 3 done