欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

检查linux网络状态的两个脚本

程序员文章站 2022-06-08 09:14:09
一、通过定时收发email检测网络连通性复制代码 代码如下:#/bin/bashecho "daily test mail" > state.txtmail -s s...

一、通过定时收发email检测网络连通性

复制代码 代码如下:

#/bin/bash
echo "daily test mail" > state.txt
mail -s server_state abc@jb51.net < state.txt
rm -df ./state.txt

~                        
crontab -e
增加如下任务
10 07 * * * /root/checknkmail &
分时日月周

二、定时检测网络状态通过email发送

checkserverstat脚本内容:

复制代码 代码如下:

#/bin/bash
echo "hztelecomdns" > state.txt
ping -c 5 202.101.172.35 >> state.txt
echo "
bju" >> state.txt
ping -c 5 10.x.x.x >> state.txt
echo "adsl gateway" >>state.txt
ping -c 5 x.x.x.x >> state.txt
echo "server_outside vpn" >>state.txt
ping -c 5 192.168.2.100 >>state.txt
echo "server_outside wan" >> state.txt
ping -c 5 x.x.x.x >> state.txt
echo "vpn in company" >> state.txt
ping -c 5 192.168.1.4 >>state.txt
echo "l2tp at aaa libweb" >>state.txt
ping -c 5 x.x.x.x & >>state.txt
mail -s server_state admin@abc.com <state.txt
rm -df ./state.txt

crontab中增加任务
复制代码 代码如下:

corntab -e
10 16 * * * /root/checkweatherstate &
10 09 * * * /root/checkserverstate &
10 13 * * * /root/checkserverstate &
10 17 * * * /root/checkserverstate &