diff options
| author | Martin Schwenke <martin@meltin.net> | 2011-08-09 13:11:38 +1000 |
|---|---|---|
| committer | Martin Schwenke <martin@meltin.net> | 2011-08-09 13:11:38 +1000 |
| commit | a684ecc8fa9c05870cc0f6bb31d5879b82ff2ac0 (patch) | |
| tree | ea8d5022531d1723bc945e87d5be235742eaac46 /ctdb/tests/eventscripts/stubs/netstat | |
| parent | 3e65cdb565aa6bc8b4379a01d385089452d26a8d (diff) | |
| parent | d8e342d71a71c1c0132e3a412f15072c155043b6 (diff) | |
| download | samba-a684ecc8fa9c05870cc0f6bb31d5879b82ff2ac0.tar.gz samba-a684ecc8fa9c05870cc0f6bb31d5879b82ff2ac0.tar.xz samba-a684ecc8fa9c05870cc0f6bb31d5879b82ff2ac0.zip | |
Merge branch 'eventscript_tests' into ronnie_target
(This used to be ctdb commit 432e6c1d5137142ce6b0314a965747524406c17e)
Diffstat (limited to 'ctdb/tests/eventscripts/stubs/netstat')
| -rwxr-xr-x | ctdb/tests/eventscripts/stubs/netstat | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/ctdb/tests/eventscripts/stubs/netstat b/ctdb/tests/eventscripts/stubs/netstat new file mode 100755 index 0000000000..cf0656651a --- /dev/null +++ b/ctdb/tests/eventscripts/stubs/netstat @@ -0,0 +1,99 @@ +#!/bin/bash + +prog="netstat" + +usage () +{ + cat >&2 <<EOF +Usage: $prog [ -t | --unix ] [ -n ] [ -a ] [ -l ] + +A fake netstat stub that prints items depending on the variables +FAKE_NETSTAT_TCP_ESTABLISHED, FAKE_NETSTAT_TCP_LISTEN, +FAKE_NETSTAT_UNIX_LISTEN, depending on command-line options. + +Note that -n is ignored. + +EOF + exit 1 +} + +# Defaults. +tcp=false +unix=false +all=false +listen=false + +parse_options () +{ + # $POSIXLY_CORRECT means that the command passed to onnode can + # take options and getopt won't reorder things to make them + # options to this script. + _temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "tnalh" -l unix -l help -- "$@") + + [ $? != 0 ] && usage + + eval set -- "$_temp" + + while true ; do + case "$1" in + -n) shift ;; + -a) all=true ; shift ;; + -t) tcp=true ; shift ;; + -l) listen=true ; shift ;; + --unix) unix=true ; shift ;; + --) shift ; break ;; + -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable. + esac + done + + [ $# -gt 0 ] && usage + + # If neither -t or --unix specified then print all. + $tcp || $unix || { tcp=true ; unix=true ; } +} + +parse_options "$@" + +if $tcp ; then + if $listen ; then + echo "Active Internet connections (servers only)" + elif $all ; then + echo "Active Internet connections (servers and established)" + else + echo "Active Internet connections (w/o servers)" + fi + + echo "Proto Recv-Q Send-Q Local Address Foreign Address State" + + tcp_fmt="tcp 0 0 %-23s %-23s %s\n" + for i in $FAKE_NETSTAT_TCP_ESTABLISHED ; do + src="${i%|*}" + dst="${i#*|}" + printf "$tcp_fmt" $src $dst "ESTABLISHED" + done + + if $all || $listen ; then + for i in $FAKE_NETSTAT_TCP_LISTEN ; do + printf "$tcp_fmt" $i "0.0.0.0:*" "LISTEN" + done + fi +fi + +if $unix ; then + if $listen ; then + echo "Active UNIX domain sockets (servers only)" + elif $all ; then + echo "Active UNIX domain sockets (servers and established)" + else + echo "Active UNIX domain sockets (w/o servers)" + fi + + echo "Proto RefCnt Flags Type State I-Node Path" + + unix_fmt="unix 2 [ ACC ] STREAM LISTENING %-8d %s\n" + if $all || $listen ; then + for i in $FAKE_NETSTAT_UNIX_LISTEN ; do + printf "$unix_fmt" 12345 "$i" + done + fi +fi |
