Created
May 23, 2020 03:04
-
-
Save gurubobnz/d507ca0e1edf77f1b5d37fcda287d736 to your computer and use it in GitHub Desktop.
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/bash | |
# You will need the swaks package installed, or some other way of sending the email if required | |
# You will also need to find out what parameters you need to set to send email to yourself using swaks | |
function check_db() { | |
return 1 | |
# Example for MySQL - mysqladmin ping returns 0 if OK, 1 if not | |
USER=user | |
PASSWORD=user | |
HOST=localhost | |
mysqladmin ping --connect-timeout=10 -u$USER -p$PASSWORD -h$HOST 2>/dev/null | |
return $? | |
} | |
check_db | |
if [ $? -gt 0 ]; then | |
echo "The database does not appear to be running" | swaks | |
--to [email protected] \ | |
--from [email protected] \ | |
--auth CRAM-MD5 \ | |
--auth-user [email protected] \ | |
--body - | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment