shell脚本
###这个是ping测试的脚本
#!/bin/bash
RED="\e[31m"
SHUTDOWN="\e[0m"
GREEN="\e[32m"
APPAY=('baidu.com' 'google.com' '172.16.114.3' '172.16.113.3' '172.16.100.201')
for APP in ${APPAY[@]}
do
ping -c1 -W1 -w 0.1 $APP &> /dev/null
if [ $? -eq 0 ]
then
echo -e "${GREEN}${APP} is running.${SHUTDOWN}" >> /data/script/for/$(date +%Y%m%d).txt
else
echo -e "${RED}"${APP}" is stop.${SHUTDOWN}" >> /data/script/for/$(date +%Y%m%d).txt
fi
done
#unse是取消变量,是担心这个脚本定义的变量影响到外面执行
unset
###判断这个网段的IP有几个是在用的IP(1个网段)
#!/bin/bash
red="\e[31m"
shutdown="\e[0m"
green="\e[32m"
for ip in {1..254}
do
ping -c 1 -W1 -w 0.1 10.112.13.${ip} &> /dev/null
if [ $? -eq 0 ]
then
echo -e "${green}10.112.13.${ip} is running.${shutdown}" >> /data/script/sh/$(date +%Y%m%d).txt
else
echo -e "${red}"10.112.13.${ip}" is stop.${shutdown}" >> /dev/null #黑洞
done
#打印行数
awk '{print NR}' ping1.txt|tail -n1
###ping测试(2个地址段)
#ping12/13网段的IP,只ping一次,ping通的打印出来,ping不通的丢弃到黑洞,最后在打印一共有多少行
#!/bin/bash
red="\e[31m"
shutdown="\e[0m"
green="\e[32m"
#for IP in {0..254}
for IP in {12..13}
do
for ip in {1..254}
do
ping -c1 -W1 -w 0.1 10.112.$IP.$ip &> /dev/null
if [ $? -eq 0 ]
then
echo -e "${green}"10.112.$IP.${ip}${shutdown}" is running." >> /data/script/sh/$(date +%Y%m%d).txt
else
echo -e "${red}"10.112.$IP.${ip}${shutdown}" is stop." >> /dev/null
fi
done
done
#打印出行数
awk '{print NR}' ip.txt | tail -n1