Skip to content

Instantly share code, notes, and snippets.

@nisdis
Forked from mheadd/monitor.sh
Last active July 27, 2017 10:18
Show Gist options
  • Save nisdis/172450727db3220bc1948dabd10a7aac to your computer and use it in GitHub Desktop.
Save nisdis/172450727db3220bc1948dabd10a7aac to your computer and use it in GitHub Desktop.
Simple bash script to check whether MySQL is running.
#!/bin/bash
##checks if mysql and apache is up and running, also can be used to start the service on Debian type systems
## Contact: nissim at companyoftwo dot in
APUP=$(pgrep apache2 | wc -l);
MYUP=$(service mysql status | wc -l);
if [ "$MYUP" -lt 2 ];
then
echo "MySQL is down.";
/usr/sbin/service mysql start
else
echo "MySQL is running...";
fi
if [ "$APUP" -eq 0 ];
then
echo "Apache2 is down.";
/usr/sbin/service apache2 start
else
echo "Apache2 is running...";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment