I have a script to check if an extension is up and it run on cron job every 30 minutes. Any thoughts on how to make the script send an email once and not every 30 minutes while the extension is down?
#!/bin/bash
email="[email protected]"
A=`/usr/sbin/asterisk -x 'sip show peer 200' | grep -i status | cut -d' ' -f11`
if [ "$A" != "OK" ]; then
(
echo "Subject: Extension 200 is down"
printf 'Extension 200 is down"...'
) | /usr/sbin/sendmail ${email}
fi
Inside your if before the email sends.
Add another if to check the variable and only email if it is 0
read emailsent < savedvar.txt
If $emailsent == 0 then
# send the email and set the variable
# set email sent variable
$emailsent=1
#write it to a file
echo $emailsent > savedvar.txt
You script is working, so don’t mess with it, but using the Asterisk ASTDB for this might not be a bad idea. You can use an "rasterisk -x ‘your_command_goes_here’ " to get and set a variable in the extension hierarchy. With that, you can then use the same variable for other fun things you might want to do with this knowledge. I don’t know what else you might want to use, but you never know.