监控网卡流量的shell脚本

简介: 监控网卡流量的shell脚本
+关注继续查看

本脚本来自有学习阿铭的博文学习:
公司网络偶尔出现网卡问题,将陷入业务瘫痪,造成不可挽回的损失。所以需要时常监控。
提示:本文中的S全部都$符,不要问为什么,马云爸爸的社区就这样。

#!/bin/bash
#用途:监控网卡流量的shell脚本。
#作者:Caron maktini
#日期:2018年11月23日
#版本:v0.1
#要求如下:每分钟检测一次网卡的流量;当网卡流量为0时,重启网卡。

mail_user=admin@admin.com 
dir=/tmp/netlog

[ -d  Sdir ] II mkdir  $dir 
s_m=`lsattr -d  Sdir l awk ' {print $1} ' I  sed  's/[^a]//g'` 
if  [  $s_m  != "a" ]
then 
    chattr +a  $dir 
fi

if  ! rpm -q sysstat &> /dev/null 
then 
    yum install -y sysstat 
fi 

sar -n DEV 10 I grep 'eth0 ' > /tmp/eth0_sar. Iog 
net_in=`grep ' ^Average: ' /tmp/eth0_sar.log l awk '{ print $5}'` 
net_out=`grep ' ^Average: ' /tmp/eth0_sar.log l awk '{ print $6}'` 


if [ ! -f $dir/net.log ] 
then 
    echo"net_in $ net_in">> S dir/net. Iog 
    echo"net_out $ net_out">> S dir/net. Iog 
    exit 0
fi 

net_in_last=`tail-2  Sdir/net.Iog l grep 'net_in'` 
net_out_last=`tail-2  Sdir/net.Iog l grep 'net_out'` 
net_in_diff=`S [Snet_in-$net_in_last]`
net_out_diff=`S [S net_out-Snet_out_last]' 

if [  Snet_in_diff  -gt  $net_in_last ]
then 
      python mail.py $mail_user "网卡入口流量増幅异常" "增幅Snet_in_dff"       
fi 

if [ Snet_out_diff -gt Snet_out_last ] 
then 

      python mail.py $mail_user "网卡出口流量增幅异常" "增幅Snet_out_dff"      
fi 

echo  "net_in Snet_in" >> $ dir/net.Iog 
echo   "net_out  Snet_out">> $ dir/net.Iog 


相关文章
|
1天前
|
Shell
shell一个斗地主的脚本
shell一个斗地主的脚本
8 1
|
19天前
|
监控 机器人 Shell
用shell脚本编写一个监控应用服务的脚本,外发到微信群
用shell脚本编写一个监控应用服务的脚本,外发到微信群
21 1
|
19天前
|
监控 关系型数据库 Shell
用shell脚本编写一个监控rds数据库外发到钉钉群的脚本
用shell脚本编写一个监控rds数据库外发到钉钉群的脚本
26 1
|
19天前
|
Shell
用shell脚本编写一个日常巡检机器脚本
用shell脚本编写一个日常巡检机器脚本
26 2
|
1月前
|
运维 Shell Linux
【运维知识高级篇】超详细的Shell编程讲解1(Shell作用+脚本书写方式+脚本执行方式+变量分类+变量配置文件+变量定义+Shell重要的位置变量+三种传参方式)
【运维知识高级篇】超详细的Shell编程讲解1(Shell作用+脚本书写方式+脚本执行方式+变量分类+变量配置文件+变量定义+Shell重要的位置变量+三种传参方式)
113 0
|
1月前
|
存储 关系型数据库 Shell
shell语言最实用的脚本练习
shell语言最实用的脚本练习
|
1月前
|
Shell Go
go 执行shell脚本 在指定目录下执行指定脚本
go 执行shell脚本 在指定目录下执行指定脚本
28 0
|
1月前
|
机器学习/深度学习 Shell Linux
Shell基础学习---1、Shell概述、脚本入门、变量
Shell基础学习---1、Shell概述、脚本入门、变量
|
1月前
|
Shell
Shell 脚本后面添加参数
Shell 脚本后面添加参数
27 0
|
1月前
|
Shell
Shell 脚本输出命令结果保持原格式,保留换行
Shell 脚本输出命令结果保持原格式,保留换行
24 0
相关产品
云迁移中心
推荐文章
更多