linux ping shell脚本,linux shell ping 脚本

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值