批量ping 查看主机能否ping通,能否ssh上.md,
[cloudop@note004 lilei]$ cat hosts_status.sh
#!/bin/bash
# 清空腳本結(jié)果文件
/tmp/cant_ssh.txt
/tmp/cat_ssh.txt
/tmp/cant_ping.txt
# shell腳本并發(fā)查看ip,具體ip列表根據(jù)個(gè)人信息更改
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
# 等待腳本執(zhí)行完畢
wait
# 輸出詳細(xì)內(nèi)容,并且排除掉外網(wǎng)ip,之保留內(nèi)網(wǎng)ip,內(nèi)網(wǎng)IP是10段的,所以排除掉,根據(jù)實(shí)際情況更改
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]$
轉(zhuǎn)載于:https://blog.51cto.com/12449902/2169838
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的批量ping 查看主机能否ping通,能否ssh上.md,的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 说一说MVC的CompressActio
- 下一篇: 你不知道的JavaScript运算符