Created
May 27, 2015 17:30
-
-
Save josue/331c21dddf6dc4c6088a to your computer and use it in GitHub Desktop.
Start/Stop mysql-sniffer and log data to file
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 | |
APP="mysql-sniffer" | |
LOG="/tmp/mysql-sniffer.log" | |
PID="" | |
get_pid () { | |
PID=`ps aux | grep "$APP" | grep -v grep | grep -v "$0" | awk '{ print $2 }'` | |
} | |
if [ "$1" = "-h" ]; | |
then | |
echo "Usage: $0 [options]" | |
echo " -k = kill running script" | |
echo " -h = Help" | |
echo | |
exit 0 | |
fi | |
get_pid | |
if [ "$PID" != "" ]; | |
then | |
if [ "$1" = "-k" ]; | |
then | |
echo "Stopping $APP (PID: $PID) ..." | |
kill -9 $PID | |
else | |
echo "Already running $APP (PID: $PID)" | |
fi | |
else | |
nohup $APP -i=lo -u -v >> $LOG 2>&1 & | |
get_pid | |
echo "Running $APP (PID: $PID)" | |
echo "- Logging to file: $LOG" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save file to /usr/bin directory then make executable: