批量ping脚本

2020-08-14 09:38:15 浏览数 (1)

代码语言:javascript复制
#!/bin/bash
#注意修改为自己需要ping的地址
M=/tmp/jiankong/`date ' %Y-%m-%d'`
if [ ! -d $M ];then
        mkdir -p $M
        echo -e "33[32mThe $M Create Successfully!33[0m"
else
        echo "This $M is exists..."
fi

for i in {41..74}
do
        ping -c 1 172.168.2.$i > /dev/null
        if [ $? -eq 0 ];then
        echo "`date ' %Y-%m-%d %H:%M:%S'` 172.168.2.$i is up!" >> "$M/up.txt"
        else
        echo "`date ' %Y-%m-%d %H:%M:%S'` 172.168.2.$i is down" >> "$M/down.txt"
        fi
done
echo "                                                        " >> "$M/up.txt"
echo "                                                        " >> "$M/down.txt"

for i in {101..168}
do
        ping -c 1 172.168.2.$i > /dev/null
        if [ $? -eq 0 ];then
        echo "`date ' %Y-%m-%d %H:%M:%S'` 172.168.2.$i is up!" >> "$M/up.txt"
        else
        echo "`date ' %Y-%m-%d %H:%M:%S'` 172.168.2.$i is down" >> "$M/down.txt"
        fi
done
echo "                                                        " >> "$M/up.txt"
echo "                                                        " >> "$M/down.txt"


for i in {11..34}
do
        ping -c 1 10.2.200.$i > /dev/null
        if [ $? -eq 0 ];then
        echo kpjy$(expr $i - 10) Extranet Work port "`date ' %Y-%m-%d %H:%M:%S'` 10.2.200.$i is up!" >> "$M/up.txt"
        else
        echo kpjy$(expr $i - 10) Extranet Work port "`date ' %Y-%m-%d %H:%M:%S'` 10.2.200.$i is down" >> "$M/down.txt"
        fi
done
echo "                                                        " >> "$M/up.txt"
echo "                                                        " >> "$M/down.txt"

0 人点赞