Wednesday, 29 May 2013

Observing tips #4 — Keeping watch

Often during observing there are tasks that require a certain amount of time to complete. Sometimes these are things that can be simply left to run and at other times you might need to keep an eye on them. Occasionally, there are also occasions when you want to monitor some system parameter on the computer. This can be easy enough to do once, but often it results in typing the command over and over (or using up-arrow / carriage return).

Let's take disk space on the file system, for instance. This is often done with the 'df' command. Now, to be a bit clever, you could put this in a loop. Here is an example (the '%' is just the prompt).

    % while true ; do df ; done

That runs it a bit fast, so we can add some wait time between iterations

    % while true ; do df ; sleep 2 ; done

Better, but still difficult to read. So, we can clear the terminal each time first.

    % while true ; do clear ; df ; sleep 2 ; done

Although the above works, and is effective, there is a simpler way, that exists on most modern Linux systems... watch!

    % watch df

This does exactly what the above command sequence was doing, but it also prints the current time, the update frequency and the command being run. If you want to monitor more complex commands, simply put them in quotes. Such as:

    % watch "ls -l"

To exit from a 'watch', press CTRL+C. There are plenty of options for it too. Just run it with the '--help' flag as:

    %  watch --help

On most versions you can control the update time, highlight differences from one update to the next, control the formatting or even get it to automatically drop out on an error.

All in all, this is a useful utility and it makes keeping tabs on those long data transfers much easier.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.