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

Posted qinshihai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了检查linux网络状态的两个脚本相关的知识,希望对你有一定的参考价值。

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

#/bin/bash
echo "Daily test mail" > state.txt
mail -s Server_State [email protected] < 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 [email protected] <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 &

 

以上是关于检查linux网络状态的两个脚本的主要内容,如果未能解决你的问题,请参考以下文章

谢烟客---------Linux之bash脚本编程---if补充和for循环

分享前端开发常用代码片段

linux 查看哪些端口被监听

收藏|分享前端开发常用代码片段

linux系统自查脚本

Linux shell脚本判断服务器网络是否可以上网