Wednesday, July 27, 2016

Running the Same Command Periodically and Watch the Output

Have you ever find yourself typing the same command over and over again just to see what's been changing? On a standard Linux, there is a little-known utility called "watch". It can run a command repeatedly every so many seconds and shows you the output. But it goes one step further by showing the differences between the last run and current by highlighting the differences. Yes, it's a clunky command line tool but does a beautiful job of saving a lot of typing and figuring out what changed. See the man pages for watch(1) for the detail and the option flags.

I often used it with SQL*Plus to see the changes in database. For example, you can have a SQL statement in a file called, say, count.sql. You can invoke it using SQL*Plus but you will see the output only one time. To see the output periodically, you can invoke it with watch(1), e.g.

watch -d sqlplus scott/tiger@xe @count

Don't forget to have "EXIT" as the last command in count.sql so that sqlplus would exit after executing the SQL statements.

No comments:

Post a Comment