批量测试 ip/domain 连通性
#!/bin/bash echo ---------------------------Start ping---------------------------- for i in `/usr/bin/cat ~/agent/ping_list/domain` do code=`ping -c 4 -W 3 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'` if [ $code -eq 100 ];then echo -e "\033[31m ping $i \t Fail \t\t packet loss: %$code \033[0m" else echo -e "\033[32m ping $i \t Success \t packet loss: %$code \033[0m" fi done echo ------------------------------Done-------------------------------
批量测试端口连通性
文本:
192.168.1.1 53 192.168.1.1 80 192.168.1.1 87 192.168.1.1 848 192.168.1.2 848
脚本:
#!/bin/bash cat testport | while read line do #nc -z -w 10 $line nc -z -w 10 $line > /dev/null 2>&1 if [ $? -eq 0 ] then echo $line:ok else echo $line:fail fi done