Skip to content

Instantly share code, notes, and snippets.

@sokolenkoDEV
Created July 31, 2018 23:53
Show Gist options
  • Save sokolenkoDEV/133e2ecafb5ed95f90b3e617b15abe2d to your computer and use it in GitHub Desktop.
Save sokolenkoDEV/133e2ecafb5ed95f90b3e617b15abe2d to your computer and use it in GitHub Desktop.
periodically check abailability of website
#!/bin/bash
WEBSITE="mybash.tk"
EMAIL="ihc.ru.test@gmail.com"
TIMER=60 #how often send emails in seconds
SLEEP_TIMER=10 # how often check availability of website
#dont change STATUS variable it's default value
STATUS=1
#PROGRAM VARIABLES
WORKTIMER=$TIMER
WORKSTATUS=$STATUS
while true; do
DATEIS=`date +"%H:%M:%S"`
echo -n $DATEIS " - "; echo -n "$WEBSITE - "
RESPOND=`curl -LI -silence $WEBSITE | grep HTTP | grep -c "200"`
if [[ "$RESPOND" -eq "0" ]]; then
if [[ $WORKSTATUS -eq "1" ]]; then
echo -e "\e[1;41mERROR: not working\e[0m"
echo "$WEBSITE not answer at $DATEIS" | mail -s "$WEBSITE wrong HTTP ANSWER" $EMAIL
if [[ $? ]]; then
echo -e "Email Has been sent to -\e[1;42m $EMAIL \e[0m";
fi
WORKSTATUS=0;
WORKTIMER=$TIMER;
echo "TIMER to next email: $((WORKTIMER))s"
elif [[ $WORKTIMER -eq "0" ]]; then
echo -e "\e[1;41mERROR: not working\e[0m"
echo "$WEBSITE not answer at $DATEIS" | mail -s "$WEBSITE wrong HTTP ANSWER" $EMAIL
if [[ $? ]]; then
echo -e "Email Has been sent to -\e[1;42m $EMAIL \e[0m";
fi
WORKTIMER=$TIMER;
else
WORKTIMER=$(( $WORKTIMER - $SLEEP_TIMER))
echo -e "\e[1;41m ERROR: still not working:\e[0m next email after "$WORKTIMER"s";
fi
else
echo -e "\e[1;43m Working well\e[0m"
WORKSTATUS=$STATUS
WORKTIMER=$TIMER
echo "Status :$WORKSTATUS TIMER: $WORKTIMER"
fi
sleep $SLEEP_TIMER ;
done
@sokolenkoDEV
Copy link
Author

how it looks - http://scr.pics/d0c1702600b28.jpg
If website is not available, an email alert will be sending to administrator.
You can easy adjust a time how often send emails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment