Skip to content

Instantly share code, notes, and snippets.

@refraction-ray
Created August 7, 2019 10:05
Show Gist options
  • Save refraction-ray/4904205f157bd79cd23b4a11c5ac2428 to your computer and use it in GitHub Desktop.
Save refraction-ray/4904205f157bd79cd23b4a11c5ac2428 to your computer and use it in GitHub Desktop.
A super light-weighted monitoring and alerting tool, if you don't want to configure any of there monitoring tools
#! /bin/bash
ips=("8.8.8.8"
"baidu.com")
webs=("http://10.0.0.1:8080")
address="user@mails.domain"
for ip in "${ips[@]}"; do
r=$(/bin/ping -c3 -W1 "${ip}"|grep received|awk '{print $4}')
if [ $r -lt 3 ]; then
echo "send mail..."
echo "${ip} cannot reached"|/usr/bin/mail -s "alert by stb" $address
fi
done
for web in "${webs[@]}"; do
r=$(curl -s "${web}"|grep 401|wc -l)
if [ $r == 0 ]; then
echo "send mail..."
echo "${web} cannot reached"|/usr/bin/mail -s "alert by stb" $address
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment