Email system status

hello everyone. i would like to get emails when asterisk reloads or looses connectivity.
i have edited the /usr/sbin/safe_asterisk but it does not do anything at all. all i am getting info is from another script that informs me when the system rebooted. is there any way to have that functionality please?
the system can send emails using the following
echo “This is Content” | mail -s “This is subject” userA@ISPmail.org

Check if the service is running with a bash script and a cronjob

this could be helpful http://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/

hi.thanks for the reply. this is checking regurarly if the system runs and emailing me. this will get me with a lot of emails without use.
i do need the opposite. when something wrong takes place, then email email me.
-asterisk reload
-sip trunk failure

Most of the time people check sip trunk failure checking the qualify value, asterisk reload just happen if you restart the service o run the reload command.

at the moment i do have at the cron a script with sends me the output of the
asterisk -rx “sip show peers” | grep trunk_name
instead of getting a lot of messages, i would like to get only the ones that have a status update in the asterisk -rx “sip show peers” | grep trunk_name

A simple solution would be to use a managed logging service and have them alert you based on your criteria.

Send your syslog messages to a service like Loggly or Papertrail or Splunk and set up an alert that emails you when it matches a search term.