Last active
August 29, 2015 14:06
-
-
Save dtanham/770d7bb2836da6395bdd to your computer and use it in GitHub Desktop.
Tcpdump restart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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