Watch: regularly repeat Linux/Unix Commands

Source: Internet
Author: User

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:

  1. 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 -fActively tracks updates to a file without using watch .). This command will run continuously until you pressCTRL + CReturn to the prompt.

 

Example

Monitors the status generated by errors, notices, and warning every two seconds.

  1. watch tail /var/log/messages

Tail messages

Monitor disk usage at specified intervals.

  1. 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.

  1. watch mysqladmin processlist

Processlist

Monitor server load and running time.

  1. watch uptime

Uptime

Monitor the size of the queue that exim sends notifications to users.

  1. watch exim -bpc

Exim-bpc

 

1) Specify the latency
  1. 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:

  1. 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.

  1. watch [-d or--differences[=cumulative]]<command>

Example 1: Use the following command to continuously output time and observe different highlighted parts.

  1. 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.

  1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.