Skip to content

Instantly share code, notes, and snippets.

@sontqq
Created June 14, 2020 05:51
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 sontqq/bdcbe8061af568739121fc66db439673 to your computer and use it in GitHub Desktop.
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
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 emailaddress@gmail.com
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment