Skip to content

Instantly share code, notes, and snippets.

@gurubobnz
Created May 23, 2020 03:04
Show Gist options
  • Save gurubobnz/d507ca0e1edf77f1b5d37fcda287d736 to your computer and use it in GitHub Desktop.
Save gurubobnz/d507ca0e1edf77f1b5d37fcda287d736 to your computer and use it in GitHub Desktop.
#!/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 user@example.com \
--from me@example.com \
--auth CRAM-MD5 \
--auth-user me@example.com \
--body -
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment