#!/bin/bash
TH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin;
export PATH
eth=eth0
# 获取当前时刻网口接收与发送的流量
RXpre=$(cat /proc/net/dev | grep $eth | tr : ” ” | awk ‘{print $2}’)
# 判断获取值若为空,则网口不存在
if [[ $RXpre == “” ]]; then
echo “Error parameter,please input the right port after run the script!”
exit 0
#!/bin/bash
TH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin;
export PATH
eth=eth0
# 获取当前时刻网口接收与发送的流量
RXpre=$(cat /proc/net/dev | grep $eth | tr : ” ” | awk ‘{print $2}’)
# 判断获取值若为空,则网口不存在
if [[ $RXpre == “” ]]; then
echo “Error parameter,please input the right port after run the script!”
exit 0
fi
TXpre=$(cat /proc/net/dev | grep $eth | tr : ” ” | awk ‘{print $10}’)
# 获取1秒后网口接收与发送的流量
sleep 1
RXnext=$(cat /proc/net/dev | grep $eth | tr : ” ” | awk ‘{print $2}’)
TXnext=$(cat /proc/net/dev | grep $eth | tr : ” ” | awk ‘{print $10}’)
clear
# 获取这1秒钟实际的进出流量
RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre}))
echo “RX:=” $RX;
echo “TX:=” $TX;
# 打印实时流量
echo -e “Date: date +%F” ” “Time: date +%k:%M:%S” $eth \t RX:$RX TX:$TX ” >> /var/log/RXlog
echo “——————————”
# 退出信息
if [ $RX -gt 1048576 ];then
/bin/bash /usr/local/bin/1.sh #满足流量大于1M的条件 就执行另一个脚本
echo -e “Date: date +%F” “Time: date +%k:%M:%S“”======= sh successfull========” >> /var/log/RXlog
else
exit
fi