watch
可以看到所有数据包的大小:
$ watch -d -n 1 ifconfig eth0
可以看到发送和接收了多少个package:
$ watch netstat -s -u
watch 是一个非常实用的命令,基本所有的 Linux 发行版都带有这个小工具,如同名字一样,watch 可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行。
直接在 watch 后面接你想运行的命令,watch 就会帮你重复运行,并把每次的结果都更新在屏幕上。
默认 watch 会以 2s 的间隔重复运行命令,你也可以用 -n 参数指定时间间隔~
还有一个实用的参数是 -d,这样 watch 会帮你高亮显示变化的区域,这样更加一目了然了~
Ctrl+c 就可以退出~
你可以拿他来监测你想要的一切命令的结果变化,比如 tail 一个 log 文件,ls 监测某个文件的大小变化,看你的想象力了~
FreeBSD和Linux下watch命令的不同
在Linux下,watch是周期性的执行下个程序,并全屏显示执行结果。
-d, --differences[=cumulative] 高亮显示变动
-n, --interval= 周期(秒)
如:watch -n 1 -d netstat -ant
而在FreeBSD下的watch命令是查看其它用户的正在运行的操作,watch允许你偷看其它terminal正在做什么,该命令只能让超级用户使用。
如何运行watch:
[root@pdc conf]# who
root ttyp0 Oct 2 21:48 (192.168.x.x)
root ttyp1 Oct 2 22:25 (192.168.x.x)
xxhui ttyp3 Oct 2 23:48 (192.168.x.x)
[root@pdc conf]# watch ttyp3
~~~~~~~~~~~~~~~~~~~~~~~~~~~
tail本身的功能是显示文件的后多少行
tail filename:显示filename后十行
tail -n filename 显示filename后n行
通过添加-f选项可以监控文件变化,文件有更新就会打印出来:tail -f filename
而且watch的原理就是重复的执行后面的命令,默认的时间间隔是2秒.
如watch -d -n 10 cat /etc/syslog.conf
每10秒打印一下/etc/syslog.conf文件,-d表示高亮变化的部分
这两个命令在监控日志文件的时候相当有用
有点注意的是经测试不能在后台运行
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watch命令详解
NAME
watch - execute a program periodically, showing output fullscreen
SYNOPSIS
watch [-dhvt] [-n ] [--differences[=cumulative]] [--help] [--interval=] [--no-title] [--version]
DESCRIPTION
watch runs command repeatedly, displaying its output (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds; use -n or --interval to specify a different interval.
The -d or --differences flag will highlight the differences between successive updates. The --cumulative option makes highlighting "sticky", presenting a running display of all positions that have ever changed. The -t or --no-title option turns off the header showing the interval, command, and current time at the top of the display, as well as the following blank line. watch will run until interrupted.
NOTE
Note that command is given to "sh -c" which means that you may need to use extra quoting to get the desired effect.
Note that POSIX option processing is used (i.e., option processing stops at the first non-option argument). This means that flags after command don't get interpreted by watch itself.
EXAMPLES
To watch for mail, you might do: watch -n 60 from
To watch the contents of a directory change, you could use: watch -d ls -l
If youre only interested in files owned by user joe, you might use: watch -d 'ls -l | fgrep joe'
You can watch for your administrator to install the latest kernel with: watch uname -r (Just kidding.)呵呵
BUGS
Upon terminal resize, the screen will not be correctly repainted until the next scheduled update. All --differences highlighting is lost on that update as well.
Non-printing characters are stripped from program output. Use "cat -v" as part of the command pipeline if you want to see them.
其实很简单,就是利用linux下的 watch 工具来做监控,方法如下:
[yejr@localhost imysql]# watch -d -n 10 "egrep ’MySQL thread|Log|Modified db pages’ innodb_status.3249 "
Every 10.0s: egrep ’MySQL thread|Log|Modified db pages’ innodb_status.3249
Thu Apr 9 10:01:12 2009
MySQL thread id 6, query id 71 localhost root Sending data
Log sequence number 2703 3443241402
Log flushed up to 2703 3442763607
Modified db pages 83325
或者:
[yejr@localhost imysql]#watch -d -n 10 "mysqladmin ext|egrep Innodb_data"
Every 10.0s: mysqladmin ext|egrep Innodb_data
Thu Apr 9 10:03:55 2009
| Innodb_data_fsyncs | 4144699 |
| Innodb_data_pending_fsyncs | 0 |
| Innodb_data_pending_reads | 0 |
| Innodb_data_pending_writes | 0 |
| Innodb_data_read | 5567172608 |
| Innodb_data_reads | 298413 |
| Innodb_data_writes | 4492881 |
| Innodb_data_written | 18549422080 |
参数解释:
-d --differences
-n --interval
不用我多说了吧,怎么样,是不是觉得很有意思
转载于:https://blog.51cto.com/aixuexi/806601