Blame tests/p_iptraf/5-test_iptraf.sh

Steve Barnes 464547
#!/bin/bash
root 2bfd68
# Author: Steve Barnes (steve@echo.id.au)
Steve Barnes 464547
Steve Barnes 464547
t_Log "Running $0 - checking iptraf runs and returns non-zero exit status."
Steve Barnes 464547
Steve Barnes 464547
TMP=/tmp/iptraf.log
Steve Barnes 464547
Steve Barnes 464547
# clean up after ourselves
Steve Barnes 464547
trap "[ -e ${TMP} ] && { /bin/rm ${TMP}; }" EXIT
Steve Barnes 464547
Steve Barnes 464547
# iptraf only be run by root
Steve Barnes 464547
[ ${EUID} -eq 0 ] || { t_Log "Not running as root, skipping this test. Non-fatal."; exit $PASS; }
Steve Barnes 464547
0d514f
if [ "$centos_ver" = "7" ] ; then
0d514f
 IPTRAF=`which iptraf-ng`
0d514f
else
0d514f
 IPTRAF=`which iptraf`
0d514f
fi
Steve Barnes 464547
PING=`which ping`
Steve Barnes 464547
STAT=`which stat`
Steve Barnes 464547
KILL=`which kill`
Steve Barnes 464547
0d514f
[ "$IPTRAF" ] || { t_Log "Failed to find iptraf binary. That ain't good..."; exit $FAIL; }
root 2bfd68
[ "$PING" ] || { t_Log "Failed to find the ping binary. That ain't good..."; exit $FAIL; }
root 2bfd68
[ "$STAT" ] || { t_Log "Failed to find the stat binary. That ain't good..."; exit $FAIL; }
root 2bfd68
[ "$KILL" ] || { t_Log "Failed to find the kill binary. That ain't good..."; exit $FAIL; }
Steve Barnes 464547
Steve Barnes 464547
# start iptraf running in the background on all interfaces, logging to a file.
Steve Barnes 464547
${IPTRAF} -i all -t 1 -B -L ${TMP} &>/dev/null
Steve Barnes 464547
Steve Barnes 464547
# give iptraf something to chew on
Steve Barnes 464547
${PING} -c 5 127.0.0.1 &>/dev/null
Steve Barnes 464547
Steve Barnes 464547
# check the our log file actually has some data in it, which it should, given that we just pinged ourselves...
Steve Barnes 464547
LOGSIZE=`stat -c '%s' ${TMP}`
Steve Barnes 464547
Steve Barnes 464547
# kill iptraf
0d514f
${KILL} -USR2 `pidof $IPTRAF`
Steve Barnes 464547
Steve Barnes 464547
# confirm our iptraf log file has something in it
0d514f
if [ ${LOGSIZE} -gt 0 ] ; then
0d514f
  t_CheckExitStatus 0
0d514f
else
0d514f
  t_Log "iptraf failed to log any traffic?!. That ain't good..."
0d514f
  t_CheckExitStatus 1
0d514f
fi
Steve Barnes 464547