Skip to content

Instantly share code, notes, and snippets.

@josue
Created May 27, 2015 17:30
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 josue/331c21dddf6dc4c6088a to your computer and use it in GitHub Desktop.
Save josue/331c21dddf6dc4c6088a to your computer and use it in GitHub Desktop.
Start/Stop mysql-sniffer and log data to file
#!/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
@josue
Copy link
Author

josue commented May 27, 2015

Save file to /usr/bin directory then make executable:

chmod +x /usr/bin/start-mysql-sniffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment