Send email when extension unreachable

Good Afternoon Colleagues
I hope you are doing good and safe.

Thanks to @Charles_Darwin , I have successfully modified the code shared by him in the below thread to match PJSIP

Here is the modified shell script:

#!/bin/bash
email="[email protected]"
/usr/sbin/asterisk -rx ‘pjsip show endpoints’ > /tmp/allExtensions.txt
offlineExtensions=cat /tmp/allExtensions.txt| grep -e 'Unavailable'
if [ -z “$offlineExtensions” ]; then
exit
else
(
echo “Subject: Offline Extensions”
printf ‘freePBX_Server_Location SIP Extensions or Trunks that are currently offline…\n’‘\n’“${offlineExtensions}”
) | /usr/sbin/sendmail ${email}
fi

Below is the crontab:
*/5 * * * * /root/trunkcheck.sh > /dev/null 2>&1

The crontab sends email every 5 minutes with list of unavailable endpoints .

May i know if there is a way to send email immediately and not periodically when an endpoint is unavailable and only send email regarding this endpoint only not all unavailable endpoints?

Best Regards

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.