标签:cap int 二次 正则表达式 net style 存在 pen sleep
由于机房搬迁,需要重新telnet看看网络是否联通
[weblogic@pays03pre_BankVerify /]$ telnet 172.29.1.159 22
Trying 172.29.1.159...
Connected to 172.29.1.159.
Escape character is ‘^]‘.
SSH-2.0-OpenSSH_5.3
1:首先准备hosts文件夹,里面保存所有你要telnet的地址,端口号都是22
2:遍历hosts里面的全部ip,然后将telnet的结果保存在 telnet_result这个文件下面
3:对文件进行二次过滤
a、看上面的打印结果,如果telnet通了,那么取"]"这个符号上面的一行,也就是Connected to 172.29.1.159.
b、再通过正则表达式取后面的ip,也就是 172.29.1.159.
c、再通过"."符号分割,取出1、2、3、4段,然后将通过的地址打印在 telnet_alive.txt这个文件里面,最后将不通的地址筛选出来放在telnet_die.txt里面
脚本:
#! /bin/bash
for i in `cat hosts`
do
sleep 1|telnet $i 22 >> /luyantest/telnet_result.txt
done
cat /luyantest/telnet_result.txt| grep -B 1 \] | grep [0-9] | awk ‘{print $3}‘ | cut -d ‘.‘ -f 1,2,3,4 > /luyantest/telnet_alive.txt
cat /luyantest/hosts /luyantest/telnet_alive.txt | sort | uniq -u > /luyantest/telnet_die.txt
[root@pays03pre_BankVerify luyantest]#
[root@pays03pre_BankVerify luyantest]# cat telnet_alive.txt
172.29.1.159
172.29.1.160
172.29.2.111
[root@pays03pre_BankVerify luyantest]#
[root@pays03pre_BankVerify luyantest]#
[root@pays03pre_BankVerify luyantest]# cat telnet_die.txt
192.168.99.100
[root@pays03pre_BankVerify luyantest]#
[root@pays03pre_BankVerify luyantest]#
[root@pays03pre_BankVerify luyantest]# cat telnet_result.txt
Trying 172.29.1.159...
Connected to 172.29.1.159.
Escape character is ‘^]‘.
SSH-2.0-OpenSSH_5.3
Trying 172.29.1.160...
Connected to 172.29.1.160.
Escape character is ‘^]‘.
SSH-2.0-OpenSSH_5.3
Trying 172.29.2.111...
Connected to 172.29.2.111.
Escape character is ‘^]‘.
SSH-2.0-OpenSSH_6.6.1
Trying 192.168.99.100...
标签:cap int 二次 正则表达式 net style 存在 pen sleep
原文地址:https://www.cnblogs.com/ddddddf0917/p/10069369.html