mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
translated
This commit is contained in:
parent
24068760b9
commit
ced362889f
@ -1,135 +0,0 @@
|
|||||||
translating---geekpi
|
|
||||||
|
|
||||||
watch - Repeat Linux / Unix Commands Regular Intervals
|
|
||||||
================================================================================
|
|
||||||
A server administrator needs to maintain the system and keep it updated and safe. A number of intrusion attempts may happen every day. There are some other activities that maintain their log. These logs are updated regularly. In order to check these updates, the commands are executed repeatedly. For example, for simply reading a file, commands like head, tail, cat etc are used. These commands need to be executed repeatedly. The watch command can be used to repeat a command at regular intervals.
|
|
||||||
|
|
||||||
### Watch Command ###
|
|
||||||
|
|
||||||
Watch is a simple command, with a few options. The basic syntax of watch command is:
|
|
||||||
|
|
||||||
watch [-dhvt] [-n <seconds>] [--differences[=cumulative]] [--help] [--interval=<seconds>] [--no-title] [--version] <command>
|
|
||||||
|
|
||||||
Watch command runs the command specified to it after every 2 seconds by default. This time is counted between the completion of command and beginning of next execution. As a simple example, watch command can be used to watch the log updates, The updates are appended at the end of the file, so tail command can be used with watch to see the updates to the file. This command continues to run until you hit CTRL + C to return to the prompt.
|
|
||||||
|
|
||||||
### Examples ###
|
|
||||||
|
|
||||||
> Keep an eye on errors/notices/warning being generated at run time every couple of seconds.
|
|
||||||
|
|
||||||
watch tail /var/log/messages
|
|
||||||
|
|
||||||
![tail messages](http://blog.linoxide.com/wp-content/uploads/2015/06/1.png)
|
|
||||||
|
|
||||||
> Keep an eye on disk usage after specified time interval.
|
|
||||||
|
|
||||||
watch df -h
|
|
||||||
|
|
||||||
![df -h](http://blog.linoxide.com/wp-content/uploads/2015/06/2.png)
|
|
||||||
|
|
||||||
> It is very important for administrators to keep an eye on high I/O wait causing disk operations especially the Mysql transactions.
|
|
||||||
|
|
||||||
watch mysqladmin processlist
|
|
||||||
|
|
||||||
![processlist](http://blog.linoxide.com/wp-content/uploads/2015/06/3.png)
|
|
||||||
|
|
||||||
> Keep an eye on server load and uptime at runtime.
|
|
||||||
|
|
||||||
watch uptime
|
|
||||||
|
|
||||||
![uptime](http://blog.linoxide.com/wp-content/uploads/2015/06/10.png)
|
|
||||||
|
|
||||||
> Keep an eye on queue size for Exim at the time a cron is run to send notices to subscribers.
|
|
||||||
|
|
||||||
watch exim -bpc
|
|
||||||
|
|
||||||
![exim -bpc](http://blog.linoxide.com/wp-content/uploads/2015/06/9.png)
|
|
||||||
|
|
||||||
### 1) Iteration delay ###
|
|
||||||
|
|
||||||
watch [-n <seconds>] <command>
|
|
||||||
|
|
||||||
The default interval between the commands can be changed with -n switch. The following command will run the tail command after 5 seconds:
|
|
||||||
|
|
||||||
watch -n 5 date
|
|
||||||
|
|
||||||
![date 5 seconds](http://blog.linoxide.com/wp-content/uploads/2015/06/4b.png)
|
|
||||||
|
|
||||||
### 2) Successive output comparison ###
|
|
||||||
|
|
||||||
If you use -d option with watch command, it will highlight the differences between the first command output to every next command output cumulatively.
|
|
||||||
|
|
||||||
watch [-d or --differences[=cumulative]] <command>
|
|
||||||
|
|
||||||
#### Example1 ####
|
|
||||||
|
|
||||||
Let’s see the successive time outputs extracted using following watch command and observe how the difference is highlighted.
|
|
||||||
|
|
||||||
watch -n 15 -d date
|
|
||||||
|
|
||||||
First time date is capture when command is executed, the next iteration will be repeated after 15 seconds.
|
|
||||||
|
|
||||||
![Difference A](http://blog.linoxide.com/wp-content/uploads/2015/06/6.png)
|
|
||||||
|
|
||||||
Upon the execution of next iteration, it can be seen that all output is exactly same except the seconds have increased from 14 to 29 which is highlighted.
|
|
||||||
|
|
||||||
![Difference A](http://blog.linoxide.com/wp-content/uploads/2015/06/6b.png)
|
|
||||||
|
|
||||||
#### Example 2 ####
|
|
||||||
|
|
||||||
Let’s experience in difference between two successive outputs of “uptime” command repeated by watch.
|
|
||||||
|
|
||||||
watch -n 20 -d uptime
|
|
||||||
|
|
||||||
![uptime](http://blog.linoxide.com/wp-content/uploads/2015/06/10.png)
|
|
||||||
|
|
||||||
Now the difference between the time is highlighted as well as the three load snapshots as well.
|
|
||||||
|
|
||||||
![10b](http://blog.linoxide.com/wp-content/uploads/2015/06/10b.png)
|
|
||||||
|
|
||||||
### 3) Output without title ###
|
|
||||||
|
|
||||||
If you don’t want to display extra details about the iteration delay and actual command run by watch then –t switch can be used.
|
|
||||||
|
|
||||||
watch [-t or --no-title] <command>
|
|
||||||
|
|
||||||
Let’s see the output of following command as an example.
|
|
||||||
|
|
||||||
watch -t date
|
|
||||||
|
|
||||||
![watch without title](http://blog.linoxide.com/wp-content/uploads/2015/06/7t.png)
|
|
||||||
|
|
||||||
### Watch help ###
|
|
||||||
|
|
||||||
Brief details of the watch command can be found by typing the following command in SSH.
|
|
||||||
|
|
||||||
watch -h [or --help]
|
|
||||||
|
|
||||||
![watch help](http://blog.linoxide.com/wp-content/uploads/2015/06/8h.png)
|
|
||||||
|
|
||||||
### Watch version ###
|
|
||||||
|
|
||||||
Run the following command in SSH terminal to check the version of watch.
|
|
||||||
|
|
||||||
watch -v [--version]
|
|
||||||
|
|
||||||
![version](http://blog.linoxide.com/wp-content/uploads/2015/06/11.png)
|
|
||||||
|
|
||||||
**BUGS**
|
|
||||||
|
|
||||||
Unfortunately, upon terminal resize, the screen will not be correctly repainted until the next scheduled update. All --differences highlight-ing is lost on that update as well.
|
|
||||||
|
|
||||||
### Summary ###
|
|
||||||
|
|
||||||
Watch is a very powerful utility for system administrators because it can be used to monitor, logs, operations, performance and throughput of the system at run time. One can easily format and delay the output of watch utility. Any Linux command / utility or script and be supplied to watch for desired and continuous output.
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: http://linoxide.com/linux-command/linux-watch-command/
|
|
||||||
|
|
||||||
作者:[Aun Raza][a]
|
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]:http://linoxide.com/author/arunrz/
|
|
@ -0,0 +1,133 @@
|
|||||||
|
watch - 定期重复Linux / Unix命令
|
||||||
|
================================================================================
|
||||||
|
服务器管理员需要维护系统并保持更新和安全。每天需要尝试大量的指令。一些其他的活动存储在日志中。这些日志定期地更新。为了检车这些更新,需要重复地执行命令。比如,为了读取一个文件需要使用head、tail、cat等命令。这些命令需要重读地执行。watch命令可以用于定期地执行一个命令。
|
||||||
|
|
||||||
|
### Watch 命令 ###
|
||||||
|
|
||||||
|
watch是一个简单的命令,只有几个选项。watch命令的基本语法是:
|
||||||
|
|
||||||
|
watch [-dhvt] [-n <seconds>] [--differences[=cumulative]] [--help] [--interval=<seconds>] [--no-title] [--version] <command>
|
||||||
|
|
||||||
|
watch命令默认每隔2秒执行后面的命令。这个时间根据的是命令执行结束到上次执行的间隔来算的。比如,watch命令可以用于监测日志更新,更新时在文件的后面追加新行,因此tail命令可以用来检测文件的更新。这个命令会持续地运行直到你按下 CTRL + C回到提示符。
|
||||||
|
|
||||||
|
### 例子 ###
|
||||||
|
|
||||||
|
> 每两秒监测 errors/notices/warning 生成的情况。
|
||||||
|
|
||||||
|
watch tail /var/log/messages
|
||||||
|
|
||||||
|
![tail messages](http://blog.linoxide.com/wp-content/uploads/2015/06/1.png)
|
||||||
|
|
||||||
|
> 用指定的时间监测磁盘的使用率。
|
||||||
|
|
||||||
|
watch df -h
|
||||||
|
|
||||||
|
![df -h](http://blog.linoxide.com/wp-content/uploads/2015/06/2.png)
|
||||||
|
|
||||||
|
> 对磁盘管理员而言关注高I/O等待导致的磁盘操作尤其是mysql事务是很重要的。
|
||||||
|
|
||||||
|
watch mysqladmin processlist
|
||||||
|
|
||||||
|
![processlist](http://blog.linoxide.com/wp-content/uploads/2015/06/3.png)
|
||||||
|
|
||||||
|
> 监测服务器负载和运行时间。
|
||||||
|
|
||||||
|
watch uptime
|
||||||
|
|
||||||
|
![uptime](http://blog.linoxide.com/wp-content/uploads/2015/06/10.png)
|
||||||
|
|
||||||
|
> 检测exim排队给用户发送通知队列的大小。
|
||||||
|
|
||||||
|
watch exim -bpc
|
||||||
|
|
||||||
|
![exim -bpc](http://blog.linoxide.com/wp-content/uploads/2015/06/9.png)
|
||||||
|
|
||||||
|
### 1) 掩饰循环 ###
|
||||||
|
|
||||||
|
watch [-n <seconds>] <command>
|
||||||
|
|
||||||
|
命令默认运行的间隔用-n改变,下面的命令会在5秒后运行后面的命令:
|
||||||
|
|
||||||
|
watch -n 5 date
|
||||||
|
|
||||||
|
![date 5 seconds](http://blog.linoxide.com/wp-content/uploads/2015/06/4b.png)
|
||||||
|
|
||||||
|
### 2) 连续输出比较###
|
||||||
|
|
||||||
|
如果你使用-d选项,它会累次地高亮第一次和下一次命令之间输出的差别。
|
||||||
|
|
||||||
|
watch [-d or --differences[=cumulative]] <command>
|
||||||
|
|
||||||
|
#### 例子 1 ####
|
||||||
|
|
||||||
|
用下面的命令连续地输出时间病观察高亮出来的不同部分。
|
||||||
|
|
||||||
|
watch -n 15 -d date
|
||||||
|
|
||||||
|
第一次执行date的输出会被捕捉,15后会会重复运行命令。
|
||||||
|
|
||||||
|
![Difference A](http://blog.linoxide.com/wp-content/uploads/2015/06/6.png)
|
||||||
|
|
||||||
|
在下一次执行时,可以看到输出除了被高亮的秒数从14到29之外其他的都一样。
|
||||||
|
|
||||||
|
![Difference A](http://blog.linoxide.com/wp-content/uploads/2015/06/6b.png)
|
||||||
|
|
||||||
|
#### 例子 2 ####
|
||||||
|
|
||||||
|
让我们来体验一下两个连续的“uptime”命令输出的不同。
|
||||||
|
|
||||||
|
watch -n 20 -d uptime
|
||||||
|
|
||||||
|
![uptime](http://blog.linoxide.com/wp-content/uploads/2015/06/10.png)
|
||||||
|
|
||||||
|
现在列出了时间和3个负载快照之间的不同。
|
||||||
|
|
||||||
|
![10b](http://blog.linoxide.com/wp-content/uploads/2015/06/10b.png)
|
||||||
|
|
||||||
|
### 3) 不带标题输出 ###
|
||||||
|
|
||||||
|
如果你不希望显示更多关于延迟和实际命令的信息可以使用-t选项。
|
||||||
|
|
||||||
|
watch [-t or --no-title] <command>
|
||||||
|
|
||||||
|
让我们看下下面例子命令的输出:
|
||||||
|
|
||||||
|
watch -t date
|
||||||
|
|
||||||
|
![watch without title](http://blog.linoxide.com/wp-content/uploads/2015/06/7t.png)
|
||||||
|
|
||||||
|
### Watch 帮助 ###
|
||||||
|
|
||||||
|
可以在ssh中输入下面的命令来得到watch的简要帮助。
|
||||||
|
|
||||||
|
watch -h [or --help]
|
||||||
|
|
||||||
|
![watch help](http://blog.linoxide.com/wp-content/uploads/2015/06/8h.png)
|
||||||
|
|
||||||
|
### Watch 版本 ###
|
||||||
|
|
||||||
|
在ssh终端中运行下面的命令来检查watch的版本。
|
||||||
|
|
||||||
|
watch -v [--version]
|
||||||
|
|
||||||
|
![version](http://blog.linoxide.com/wp-content/uploads/2015/06/11.png)
|
||||||
|
|
||||||
|
**问题**
|
||||||
|
|
||||||
|
不幸的是,在终端大小调整时,屏幕不能在下次运行前重画。所有用--difference高亮的内容也会在更新时丢失。
|
||||||
|
|
||||||
|
### 总结 ###
|
||||||
|
|
||||||
|
watch对系统管理员而言是一个非常强大的工具因为它可以用于监控、日志、运维、性能和系统运行时的吞吐量。人们可以非常简单地格式化和推延watch的输出。任何Linux命令/程序或脚本可以按照所需监测和连续输出。
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: http://linoxide.com/linux-command/linux-watch-command/
|
||||||
|
|
||||||
|
作者:[Aun Raza][a]
|
||||||
|
译者:[geekpi](https://github.com/geekpi)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]:http://linoxide.com/author/arunrz/
|
Loading…
Reference in New Issue
Block a user