Watch: regularly repeat Linux/Unix Commands
The server administrator must maintain the system and maintain updates and security. Run a large number of commands every day. Some system processes record logs. These logs are constantly updated. To check for these updates, you must execute the command again. For example, to read a log file, you need to use commands such as head, tail, and cat. These commands must be executed repeatedly. The watch command can be used to regularly execute a command.
Watch command
Watch is a simple command with only a few options. The basic syntax of the watch command is:
watch [-dhvt][-n <seconds>][--differences[=cumulative]][--help][--interval=<seconds>][--no-title][--version]<command>
By default, the watch command runs the following command every 2 seconds. This time is calculated based on the interval from the end of command execution to the last execution. For example, the watch command can be used to monitor log updates. An update appends new content to the end of a file. Therefore, you can use the tail command to detect file updates.tail -f
Actively tracks updates to a file without using watch .). This command will run continuously until you pressCTRL + C
Return to the prompt.
Example
Monitors the status generated by errors, notices, and warning every two seconds.
watch tail /var/log/messages
Tail messages
Monitor disk usage at specified intervals.
watch df -h
Df-h
For disk administrators, it is important to focus on disk operations caused by high I/O waits, especially mysql transactions.
watch mysqladmin processlist
Processlist
Monitor server load and running time.
watch uptime
Uptime
Monitor the size of the queue that exim sends notifications to users.
watch exim -bpc
Exim-bpc
1) Specify the latency
watch [-n <seconds>]<command>
The default running interval of the command can be changed by-n. The following command will run the following command in five seconds:
watch -n 5 date
Date 5 seconds
2) continuous output comparison
If you use the-d option, it will repeatedly highlight the differences between the first and next commands.
watch [-d or--differences[=cumulative]]<command>
Example 1: Use the following command to continuously output time and observe different highlighted parts.
watch -n 15-d date
The output of the first date execution will be recorded, and the command will be run again in 15 seconds.
Difference
During the next execution, we can see that the output values are the same except the highlighted seconds from 14 to 29.
Difference
Example 2: Let's try different output of two consecutive "uptime" commands.
watch -n 20-d uptime
Uptime
The differences between the time and the three load snapshots are listed.
10b
3) output without titles
If you do not want to display