The watch Linux command line tool

I'm sure everyone else already knows about watch, but it's new to me. This little utility executes a program repeatedly at a set interval and displays its output.

I've been using it with mysqladmin's processlist command like this:


watch -n 1 /usr/bin/mysqladmin -uroot -pMYPASSWORD  processlist

Note that this does put your password on display at the top of the command window whilst watch is running. If you don't want that, you could write a little bash script instead like this one from a friend of mine:


#!/bin/sh

while :
do
sleep 1
clear
mysqladmin -uroot -pMYPASSWORD processlist 
done

Either way, we get a display of the MySQL process list every second in a Terminal window and it becomes very easy to see which processes are causing trouble.

7 Responses to “The watch Linux command line tool”

  1. 1 Henrik Olsen

    Watch is nice. But for this purpose you could also use mytop.

  2. 2 Dave Marshall

    Watch is cool, but mytop is a neat little replacement for what you're doing.

    http://jeremy.zawodny.com/mysql/mytop/

  3. 3 Rob...

    Thanks for the heads up on mytop :)

    Regards,

    Rob...

  4. 4 Rob T.

    While mytop and friends are better for this particular task, it is worth pointing out
    that mysql, mysqldump, etc. take an argument --defaults-file=filename. This allows you to put the user name & password in a file that won't show up in the process list.

    --Rob T.

  5. 5 Rob...

    Thanks Rob!

    Of course, one reason that I post about what I've learnt is so that people who know more than I do can chip in :)

    Regards,

    Rob...

  6. 6 LesTR

    Do while was not necessary.
    lestr@lestr-nb:~$ export MYUSER="root"
    lestr@lestr-nb:~$ echo $MYUSER
    root
    lestr@lestr-nb:~$ mysqladmin -u $MYUSER processlist
    +-----+------+-----------+----+---------+------+-------+------------------+
    | Id | User | Host | db | Command | Time | State | Info |
    +-----+------+-----------+----+---------+------+-------+------------------+
    | 218 | root | localhost | | Query | 0 | | show processlist |
    +-----+------+-----------+----+---------+------+-------+------------------+
    lestr@lestr-nb:~$

    But mtop is better : ))

  7. 7 Dave

    Hey Rob. Put your password in ~/.my.cnf :)

The views expressed in these comments are not the views of the publisher. However, we believe in the rights of others to express their legitimate views and concerns. Any legitimate complaint emailed to rob@akrabat.com will be seriously considered and the post reviewed as desirable and necessary.

Leave a Reply

Buy now!