Created
February 8, 2011 12:40
-
-
Save NicolaeNMV/816383 to your computer and use it in GitHub Desktop.
HTTP monitor sms alert
This file contains hidden or 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
#!/bin/bash | |
send_time_file="http_alerts_last_fail_sms.txt" | |
# Details http://prinfum.wordpress.com/2011/02/08/alerte-sms-cind-cade-siteul/ | |
# To edit | |
cd /home/unde_va_fi_scris_fisierul_Care_Salveaza_Ora | |
function test { | |
# To edit | |
h=`curl --connect-timeout 60 --max-time 60 http://siteulvostru.com | grep "un careva text din html"` | |
if (( ("$?" != "0") || ("${#h}" == "0") )); then | |
return 0 # Failure | |
else | |
return 1 | |
fi | |
} | |
function send_sms_delay { | |
now=`date --utc +%s` | |
last=`cat $send_time_file` | |
last=`expr $last + 1` # This will cast to int, if last was empty | |
dif=$(( $now - $last )) | |
if (( ($dif > 3600) )); then | |
return 0 | |
fi | |
return 1 | |
} | |
function send_sms_post_send { | |
now=`date --utc +%s` | |
echo $now > $send_time_file | |
} | |
function send_sms { | |
send_sms_delay | |
if [ $? -ne 0 ]; then | |
echo "Sms-ul a fost trimis nu demult" | |
return 1 | |
fi | |
echo "Send sms !" | |
# To edit | |
curl "http://api.clickatell.com/http/sendmsg?user=UTILIZATOR&password=PAROLAPUBLICA&api_id=APIID&to=373NUMARTELEFON&text=TEXTULSMS" & | |
send_sms_post_send | |
} | |
test | |
if (( ("$?" == "0") )); then | |
echo "TEst faild, wait 30 seconds" | |
sleep 30 | |
test | |
if (( ("$?" == "0") )); then | |
send_sms | |
fi | |
else | |
echo "Is up!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment