由于现网有时候要测试很多端口的连通性,所以就写了个小脚本,实现批量测试
将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;
本文出自 “风声水起” 博客,请务必保留此出处http://linuxybird.blog.51cto.com/5689151/1411281
shell脚本-批量telnet,布布扣,bubuko.com
原文:http://linuxybird.blog.51cto.com/5689151/1411281