监控网卡流量的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编程
Shell脚本入门:从基础到实践,轻松掌握Shell编程
|
1天前
|
关系型数据库 MySQL Shell
在Centos7中利用Shell脚本:实现MySQL的数据备份
在Centos7中利用Shell脚本:实现MySQL的数据备份
|
3天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
20 5
|
3天前
|
Shell 程序员 数据安全/隐私保护
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
|
3天前
|
存储 Shell C语言
shell脚本 编程 变量 基本入门(详解)
shell脚本 编程 变量 基本入门(详解)
|
4天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
13 3
|
9天前
|
弹性计算 运维 监控
|
监控 Shell
监控网卡实时流量shell脚本
监控网卡实时流量shell脚本
145 0
|
9天前
|
存储 弹性计算 运维
自动化收集员工信息的Shell脚本
【4月更文挑战第30天】
10 0
|
10天前
|
弹性计算 运维 Shell
使用shell 脚本打印图形3
【4月更文挑战第29天】
21 0