jump to navigation

Monitor your Linux box with the ” watch ” Command January 21, 2011

Posted by Tournas Dimitrios in Linux.

watch command is a really neat tool which does a simple but incredibly useful thing: it repeatedly runs a given command line and shows you the output. So, you’re effectively monitoring a progress of some process by watching relevant files.  The default interval is 2 seconds, which gives enough dynamics for most of the needs , but can also be customised . You can execute any Unix command using watch command . Watch command will be executed until you terminate it either by CTRL+C or kill the process.

watch is probably the most easy to use command line utility of the Linux operating system , with just a few switch options . This article will shows some practical examples . Of course the possibilities are endless , just use your imagination 🙂

Practical examples with  ” watch”
  • watch  ‘tail  /var/log/secure |grep  -i “failed login” | tee failed-login.db’
  • watch lastb |tee failed-login.db
continuously check  for failed “log-in” attempts
watch ‘ ls  -lh /tmp |fgrep user1’ List all files that belongs to “user1”
watch  ‘df -h |grep /dev/hda1 |tee size-of-root-partition.db’ The “root” partition is very critical to the Linux operating system .Read the file with crontab and get notified if the size exceed your predefined limit
watch  ‘free |grep -i swap’ Check your swap space
watch ‘cat /proc/meminfo’ Continuously watch statistics for your system’s memory
watch who Who is logged in your system . To focus on specific user , make use of grep


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s