由于现网有时候要测试很多端口的连通性,所以就写了个小脚本,实现批量测试
将telnet成功的写入到telnet_alive.txt中,失败则写入telnet_die.txt中
#!/bin/bash
#this script test UP to other host.
#Iplist=/opt/script_test/iplist.data
Portnumber=7001
for ip in $(cat iplist.data)
do
(sleep 1;)|telnet $ip $Portnumber >>telnet_result.txt
done
cat telnet_result.txt|grep -B 1 \]|grep [0-9]|awk ‘{print $3}‘|cut --delimiter . --fields 1,2,3,4>telnet_alive.txt
comm -23 iplist.data telnet_alive.txt>telnet_die.txt
#cat telnet_result.txt telnet_alive.txt|sort|uniq -u >telnet_die.txt
rm -rf telnet_result.txt
exit 0;
shell脚本-批量telnet
时间: 2024-10-18 05:53:45