码迷,mamicode.com
首页 > 其他好文 > 详细

批量ping 查看主机能否ping通,能否ssh上.md,

时间:2018-09-03 19:23:33      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:并且   for   uniq   bash   shell   wait   $1   echo   127.0.0.1   

[cloudop@note004 lilei]$ cat hosts_status.sh
#!/bin/bash
# 清空脚本结果文件

/tmp/cant_ssh.txt
/tmp/cat_ssh.txt
/tmp/cant_ping.txt

# shell脚本并发查看ip,具体ip列表根据个人信息更改
for n in $(awk ‘{print $1}‘ /etc/hosts |uniq |grep -v ‘127.0.0.1‘)
do
{
ping -w 2 -c 2 $n 1>/dev/null 2>&1
if [ $? -eq 0 ]
then
ssh $n ‘hostname‘ 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
echo $n >>/tmp/cant_ssh.txt # 不能ssh上的ip
else
echo $n >>/tmp/cat_ssh.txt # 能ssh上的ip
fi
else
echo $n >>/tmp/cant_ping.txt # 不能ping通的ip
fi
}&
done
# 等待脚本执行完毕
wait
# 输出详细内容,并且排除掉外网ip,之保留内网ip,内网IP是10段的,所以排除掉,根据实际情况更改
echo "sh $0 is done"
SSHOK=$(cat /tmp/cat_ssh.txt |grep ^10 |wc -l)
echo "$SSHOK master SSH is ok , info to read /tmp/cat_ssh.txt"
SSHDOWN=$(cat /tmp/cant_ssh.txt |grep ^10 |wc -l)
echo "$SSHDOWN master cant ssh , info to read /tmp/cant_ssh.txt"
PINGDONE=$(cat /tmp/cant_ping.txt |grep ^10 |wc -l)
echo "$PINGDONE master cant ping , info to read /tmp/cant_ping.txt"
[cloudop@note004 lilei]$

批量ping 查看主机能否ping通,能否ssh上.md,

标签:并且   for   uniq   bash   shell   wait   $1   echo   127.0.0.1   

原文地址:http://blog.51cto.com/12449902/2169838

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!