- #!/usr/bin/ksh93
- #
- # simple netstat -n parser
- #
- nsout="$(LC_ALL='POSIX' netstat -n)"
- while read i ; do
- leftover="${i/~(Elrx)
- (tcp|tcp6|udp) # Proto
- [[:space:]]+
- ([[:digit:]]+) # Recv-Q
- [[:space:]]+
- ([[:digit:]]+) # Send-Q
- [[:space:]]+
- ([^[:space:]]+) # Local Address
- [[:space:]]+
- ([^[:space:]]+) # Foreign Address
- [[:space:]]+
- ([^[:space:]]+) # State
- /X}"
- # if the regex above did not match then .sh.match remains
- # untouched.
- # so we check the leftover whether it just contains the
- # dummy value of "X" to indicate a successful regex match
- if [[ "$leftover" == 'X' ]] ; then
- print -v .sh.match
- else
- :
- #printf "leftover=%q\n" "${leftover}"
- fi
- done <<<"$nsout"
- # EOF.
ksh93 netstat -n parser
Posted by Anonymous on Thu 23rd Feb 2023 21:33
raw | new post
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.