while :
do
/sbin/iwconfig eth0 | grep Link | tr '\n' '\r'
Done
The script outputs the search, and then the tr command formats the
output. The result is a simple animation of a constantly updated single line
of information:
Click here to view code image
Link Quality:92/92 Signal level:-11 dBm Noise level:-102 dBm
You can also use this technique to create a graphical monitoring client for
X that outputs traffic information and activity about a network interface:
Click here to view code image
#!/bin/sh
xterm -geometry 75x2 -e \
bash -c \
"while :; do \
/sbin/ifconfig eth0 | \
grep 'TX bytes' |
tr '\n' '\r' ; \
done"
This simple example uses a bash command-line script (enabled by -c) to
execute a command line repeatedly. The command line pipes the output of
the ifconfig command through grep, which searches the output of
ifconfig and then pipes a line containing the string “TX bytes” to
the tr command. The tr command then removes the carriage return at the
end of the line to display the information inside an /xterm X11 terminal
window, automatically sized by the -geometry option:
Click here to view code image
RX bytes:4117594780 (3926.8 Mb) TX bytes:452230967 (431.2 Mb)
Endless loops can be so useful that Linux includes a command that
repeatedly executes a given command line. For example, you can get a
quick report about a system’s hardware health by using the sensors
command. Instead of using a shell script to loop the output endlessly, you
can use the watch command to repeat the information and provide simple
animation:
Click here to view code image
matthew@seymour:~$ watch "sensors -f | cut -c 1-20"
In pdksh and bash, use the following format for the while flow control