I've made a simple bash script to check if a web server responds, and to send emails to a list of addresses if the website is down. Any suggestions as to how to improve it/ edge cases that I missed/ better styling/ etc? I'm not very familiar with idiomatic bash.
#!/bin/sh
output=$(wget http://lon3213:8111 2>&1)
pattern="connected"
path="/remote/users/my_user/projects/cmb_pinger/"
# File where I check and write the status of the server
# so I don't end up sending more e-mails for the same
# downtime. It writes 0 if no email has been sent yet
# and 1 if the email has been already sent.
log="check"
emails="email1@example.com,email2@example.com"
# Create file if it doesn't exist
if ! [[ -f "$path$log" ]]
then
echo "0" > "$path$log"
fi
# Website cannot be reached
if [[ ! "$output" =~ "$pattern" ]]
then
# Emails have not yet been sent
if [[ $(cat "$path$log") == "0" ]]; then
echo "$output" | mail -s "Dashboard is down" $emails
echo "1" >| "$path$log"
fi
else
echo "0" >| "$path$log"
fi