Sunday, April 19, 2009

Using the watch command in linux

A small tutorial for using watch to monitor things in Linux.
First and foremost get a shell
root@dorkbox:~#watch --help
gives us some basic help on using watch of course there is also the man page
root@dorkbox:~#man watch
OK so for now lets not worry about any usage flags but instead focus on the using the command. We can use the command for many things but let's look at using it with monitoring or memory usage. To find out about memory usage you can use the following command.
root@dorkbox:~# cat /proc/meminfo

This will return something like the following.
MemTotal: 623008 kB
MemFree: 35336 kB
Buffers: 85560 kB
Cached: 137220 kB
SwapCached: 24480 kB

Notice that this is the truncated output.

So now lets command the two commands and combine them to continuously show our memory usage.

root@dorkbox:~# watch cat /proc/meminfo

Which will give us the following:
Every 2.0s: cat /proc/meminfo Sun Apr 19 01:20:01 2009

MemTotal: 623008 kB
MemFree: 46396 kB
Buffers: 82636 kB
Cached: 131044 kB
SwapCached: 24480 kB

Again the output is truncated.

As you see the output will be updated every 2.0 seconds.

We will look at more later on.

No comments: