[TAG] Talkback:171/grebler.html

Ben Okopnik ben at linuxgazette.net
Tue Feb 2 20:45:42 MSK 2010


[ CC to author ]

On Tue, Feb 02, 2010 at 09:40:44AM +0000, Neil Youngman wrote:
> Thanks for this interesting article. If I may offer a small "improvement"
> 
> Rather than using the loop
> 
>         while true
> 	do
> 		netstat -na | wc
> 		sleep 1
> 	done
> 
> I would use the watch command, e.g.
> 
>         watch -n 2 -d 'netstat -na | wc'
> 
> This seems to be included in both Redhat and Debian, so I guess it's 
> reasonably portable. It's advantages over handcrafting a loop are
> 
> 1. Brevity
> 2. The default display shows the command being run and the update interval
> 3. Some of the extra options are useful. I find the '-d' switch, which 
> highlights differences, can be particularly useful.

That came to my mind while I was editing Henry's article - I'm a big fan
of 'watch', myself. Do note, however, that he's operating in a mixed
environment - and, as I recall, 'watch' is not a part of the standard
Solaris toolkit (although it's available at Sunfreeware.com), and I
don't know anything about 'watch' in FreeBSD. So, portability is
probably pretty important. As to brevity, well - as long as it's still
readable, anything goes, right? :)

``
while netstat -na|wc; do sleep 1; done
''


-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *





More information about the TAG mailing list