Skip to content

Instantly share code, notes, and snippets.

@dtanham
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtanham/770d7bb2836da6395bdd to your computer and use it in GitHub Desktop.
Save dtanham/770d7bb2836da6395bdd to your computer and use it in GitHub Desktop.
Tcpdump restart
#!/bin/sh
#
# Startup script for persistent tcpdump
#
PCAP=/data/tcpdump/tcpdump.pcap
SIZE=100
COUNT=20
PIDFILE=/var/run/tcpdump
start() {
if [ -f $PIDFILE ]; then
echo "PID File $PIDFILE exists"
exit 1
fi
tcpdump -nn -w $PCAP -s0 -C $SIZE -W $COUNT -Z root not port 22 > /dev/null 2>&1 &
echo $! > $PIDFILE
exit 0
}
stop() {
if [ ! -f $PIDFILE ]; then
echo "PID File $PIDFILE does not exist"
exit 1
fi
kill -HUP `cat $PIDFILE` && rm $PIDFILE
exit $@
}
status() {
if [ ! -f $PIDFILE ]; then
echo "PID File $PIDFILE does not exist"
exit 0
fi
ps -fp `cat $PIDFILE`
exit 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment