Created
June 14, 2020 05:51
-
-
Save sontqq/bdcbe8061af568739121fc66db439673 to your computer and use it in GitHub Desktop.
Bash script for checking linux service status and sends mail if its down
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
declare -a SERVICES=( | |
nginx | |
mysql | |
testservice | |
) | |
for i in "${SERVICES[@]}"; do | |
systemctl is-active --quiet "$i" && STATUS="active" || STATUS="notactive" | |
if [ "${STATUS}" = "active" ]; then | |
echo "" | |
else | |
echo "SERVICE $i IS NOT ALIVE! FIX IT!" | ssmtp [email protected] | |
exit 1 | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment