LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 653|回复: 3

shell scripting- monitor error packets on a network interface

[复制链接]
发表于 2006-2-2 00:12:35 | 显示全部楼层 |阅读模式

  1. stp=3
  2. until [ $stp = 0 ]
  3. do
  4. ifconfig eth1 | sed -n '2p;5p;6p;8p' >> log

  5. p1=$(tail -11 log | sed -n '4p' | awk '{print $6}' | awk -F: '{print $2}')
  6. p2=$(tail log | sed -n '10p' | awk '{print $6}' | awk -F: '{print $2}')

  7. p3=$((($p2 - $p1)/2))
  8. echo $p3 "bytes per-second downloading" >> log


  9. date >> log
  10. echo '-------------------------------------------------------' >> log
  11. tail -7 log
  12. sleep 2
  13. done
复制代码


this script monitors a NIC on the computer, refreshes every 2 sec. write the resualt into a log file with time appended
it also caculated the download speed in the last 2 sec of the computer

it is a very simple script
any comments about make it better or more useful?

thanks
发表于 2006-2-2 23:30:01 | 显示全部楼层
Post by ivyharry

  1. stp=3
  2. until [ $stp = 0 ]
  3. do
  4. ifconfig eth1 | sed -n '2p;5p;6p;8p' >> log

  5. p1=$(tail -11 log | sed -n '4p' | awk '{print $6}' | awk -F: '{print $2}')
  6. p2=$(tail log | sed -n '10p' | awk '{print $6}' | awk -F: '{print $2}')

  7. p3=$((($p2 - $p1)/2))
  8. echo $p3 "bytes per-second downloading" >> log


  9. date >> log
  10. echo '-------------------------------------------------------' >> log
  11. tail -7 log
  12. sleep 2
  13. done
复制代码


this script monitors a NIC on the computer, refreshes every 2 sec. write the resualt into a log file with time appended
it also caculated the download speed in the last 2 sec of the computer

it is a very simple script
any comments about make it better or more useful?

thanks

  1. ifconfig if_name|grep "TX bytes" | awk -F: '{print $3}' | awk '{print $1}'
复制代码

The above can catch the bytes too. Would it be easier? Also, its not necessary to put everything to the log file, the whole procedure can be done in memory.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-4 03:13:56 | 显示全部楼层
thx for replying
think your way is better than mine
actually faster

and , yea..i am also considering what should go into the log file
this log file will be 18MB if u run this script for one whole day
so what u think will be useful for an admin to monitor the NIC?

thanks
回复 支持 反对

使用道具 举报

发表于 2006-2-4 03:31:56 | 显示全部楼层
Have a look at RRD.
http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/
It seems to be able to save some space.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表