0

I am running a FreeBPX on centos server and I would like to monitor phone extensions when they go offline. I have a script that is doing the job and I am running it on cron job every 30 minutes but I would like to get the email notification once and only if there is a change so I do not get the same email every 30 minute.

#!/bin/bash
email="myemail@gmail.com"
/usr/sbin/asterisk -rx 'sip show peers' > /tmp/allExtensions.txt
offlineExtensions="cat /tmp/allExtensions.txt| grep 'UNKNOWN'"
count="cat /tmp/allExtensions.txt | wc -l"
if [ $count -gt 0 ]; then
(
echo "Subject: Offline Extensions"
printf 'Extensions that are currently offline...\n''\n'"${offlineExtensions}"
) | /usr/sbin/sendmail ${email}
fi

I would also like to exclude some extensions such as '203' as they are not important. The output of

cat /tmp/allExtensions.txt| grep 'UNKNOWN' 
205/205     (Unspecified)     D     Yes     Yes     A     0     UNKNOWN
  1. I would like some help modifying the script so that emails will be send once. For example the cron will run every 30 minutes but if extensions 201 and 202 are UNKNOWN then I will get one email. If after 30 minutes there is another extension 205 is UNKNOWN the will get an email notification.
  2. Also I would like to exclude some extensions "203" from triggering the notification if possible.
  • Hi and welcome to UX.SE. We greatly appreciate when people take care describing what they are doing. You did that very well. However, it is not clear what you are asking for. You have to state a definitive question you would like answered. Merely asking for suggestions is too broad, b/c even "grab a beer" would be a valid answer here. Please state a concrete problem you would like help with – Bananguin May 22 '19 at 21:48
0

I was able to achieve the intended outcome using the script below.

#!/bin/sh
email="myemail@yahoo.com"
/usr/sbin/asterisk -x 'sip show peer 204' | grep -i status | cut -d' ' -f11 >             /tmp/204status1.txt
A=`comm -23 /tmp/204status1.txt /tmp/204status2.txt`
cp /tmp/204status1.txt /tmp/204status2.txt
if [ "$A" == "UNKNOWN" ]; then
(
echo "Subject: System is down - 204"
printf 'System is down...'
) | /usr/sbin/sendmail ${email}
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.