[Classiccity-pm] cute perl one-liner

Paul Keck pkeck at uga.edu
Thu Aug 5 09:51:33 CDT 2004


I was troubleshooting a network problem a while back and a good way to watch
things was to set up a continuous ping.  Trouble is, when you're across the
room and the ping gets past a certain point, there is no obvious change to
the screen even if it's still working fine.  So I piped the ping results
into a perl one-liner and prepended a random number of spaces to the
beginning of the line:

ping 128.192.1.1  |perl -n -e 'print  " " x rand(5), $_'

which looks like

pkeck at hodag:~$ ping 128.192.1.1  |perl -n -e 'print  " " x rand(5), $_'
   PING 128.192.1.1 (128.192.1.1): 56 data bytes
  64 bytes from 128.192.1.1: icmp_seq=0 ttl=63 time=0.2 ms
    64 bytes from 128.192.1.1: icmp_seq=1 ttl=63 time=0.2 ms
    64 bytes from 128.192.1.1: icmp_seq=2 ttl=63 time=0.2 ms
  64 bytes from 128.192.1.1: icmp_seq=3 ttl=63 time=1.9 ms
   64 bytes from 128.192.1.1: icmp_seq=4 ttl=63 time=1.4 ms
  64 bytes from 128.192.1.1: icmp_seq=5 ttl=63 time=1.6 ms
   64 bytes from 128.192.1.1: icmp_seq=6 ttl=63 time=4.9 ms
   64 bytes from 128.192.1.1: icmp_seq=7 ttl=63 time=1.5 ms

and as this scrolls up the screen it is obvious when it stops.

If you like noise you could also have it print an "alarm" character, which
beeps on most terminals:

ping 128.192.1.1  |perl -n -e 'print  " " x rand(5), "\a",  $_'

And yes, you could do this with sed or awk or any number of other languages. 
Anyone have a similar situation when it would come in handy?


-- 
Paul Keck       pkeck at uga.edu         http://www.arches.uga.edu/~pkeck
University of Georgia                 http://www.uga.edu/ucns/telecom
EITS Network Engineering              mailto:pkeck at ediacara.org
    --Opinions mine.--                Go fighting anomalocaridids!!!


More information about the Classiccity-pm mailing list