Skip to content

Instantly share code, notes, and snippets.

@somoza
Created December 26, 2019 13:25
Show Gist options
  • Save somoza/62bb8ef9a7033d5e2466f8310979adfb to your computer and use it in GitHub Desktop.
Save somoza/62bb8ef9a7033d5e2466f8310979adfb to your computer and use it in GitHub Desktop.
Bash to check apache status, restart it and send telegram bot.
#!/bin/bash
telegram=(xxxxx, yyyyyy)
if ! pidof apache2 > /dev/null
then
# web server down, restart the server
echo "Server down"
/etc/init.d/apache2 restart > /dev/null
sleep 10
#checking if apache restarted or not
if pidof apache2 > /dev/null
then
for i in "${telegram[@]}"
do
curl -s -X POST https://api.telegram.org/botxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyy/sendMessage -d chat_id="$i" -d text="`echo -e '\U0001F525'` Apache stoped on Molib Stage. Automatically restarted succesfully."
done
else
for i in "${telegram[@]}"
do
curl -s -X POST https://api.telegram.org/botxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyy/sendMessage -d chat_id="$i" -d text="`echo -e '\U0001F525'` Apache stoped on Molib Stage. Automatically restart failed. Please check manually."
done
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment