栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

watch命令实现Linux监控

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

watch命令实现Linux监控

watch命令简介

watch命令可以重复的执行命令,并且将其输出在命令行上,可以方便的实现一些简单的监控

 watch -n 1 cat 1.txt

上面的这个命令输出1.txt的内容,-n 1表示每隔一秒钟执行一次命令


右侧shell执行命令,左侧是watch的输出

我们可以看到先是输出了wdnmd,然后输出了nmsl,至此,我们很简单的实现了一个不断变化的文件的监控,但它是实用的——比如监控一个动态变化的log日志

另一个小例子:在所有进程中查找是否有node关键字的进程,每隔三秒刷新一次

 watch -n 3 "ps aux | grep node"
example
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 you're only interested in files owned by user joe, you might use
              watch -d 'ls -l | fgrep joe'
       To see the effects of quoting, try these out
              watch echo $$
              watch echo '$$'
              watch echo "'"'$$'"'"
       To see the effect of precision time keeping, try adding -p to
              watch -n 10 sleep 1
       You can watch for your administrator to install the latest kernel with
              watch uname -r
       (Note that -p isn't guaranteed to work across reboots, especially in the face of ntpdate or other bootup time-changing mechanisms)

option
OPTIONS
       -d, --differences [permanent]
              Highlight the differences between successive updates.  Option will read optional argument that changes highlight to be  permanent,  allowing  to
              see what has changed at least once since first iteration.

       -n, --interval seconds
              Specify  update  interval.  The command will not allow quicker than 0.1 second interval, in which the smaller values are converted. Both '.' and
              ',' work for any locales.

       -p, --precise
              Make watch attempt to run command every interval seconds. Try it with ntptime and notice how the fractional seconds stays (nearly) the same,  as
              opposed to normal mode where they continuously increase.

       -t, --no-title
              Turn off the header showing the interval, command, and current time at the top of the display, as well as the following blank line.

       -b, --beep
              Beep if command has a non-zero exit.

       -e, --errexit
              Freeze updates on command error, and exit after a key press.

       -g, --chgexit
              Exit when the output of command changes.

       -c, --color
              Interpret ANSI color and style sequences.

       -x, --exec
              Pass command to exec(2) instead of sh -c which reduces the need to use extra quoting to get the desired effect.

       -h, --help
              Display help text and exit.

       -v, --version
              Display version information and exit.
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/826432.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号