pastebin - collaborative debugging tool
rovema.kpaste.net RSS


ksh93 netstat -n parser
Posted by Anonymous on Thu 23rd Feb 2023 21:33
raw | new post

  1. #!/usr/bin/ksh93
  2.  
  3. #
  4. # simple netstat -n parser
  5. #
  6. nsout="$(LC_ALL='POSIX' netstat -n)"
  7.  
  8. while read i ; do
  9.         leftover="${i/~(Elrx)
  10.                 (tcp|tcp6|udp)  # Proto
  11.                 [[:space:]]+
  12.                 ([[:digit:]]+)  # Recv-Q
  13.                 [[:space:]]+
  14.                 ([[:digit:]]+)  # Send-Q
  15.                 [[:space:]]+
  16.                 ([^[:space:]]+) # Local Address
  17.                 [[:space:]]+
  18.                 ([^[:space:]]+) # Foreign Address
  19.                 [[:space:]]+
  20.                 ([^[:space:]]+) # State
  21.                 /X}"
  22.        
  23.         # if the regex above did not match then .sh.match remains
  24.         # untouched.
  25.         # so we check the leftover whether it just contains the
  26.         # dummy value of "X" to indicate a successful regex match
  27.         if [[ "$leftover" == 'X' ]] ; then
  28.                 print -v .sh.match
  29.         else
  30.                 :
  31.                 #printf "leftover=%q\n" "${leftover}"
  32.         fi
  33. done <<<"$nsout"
  34. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at