adblock.notify 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. #
  3. # adblock send mail script for mstmp
  4. # written by Dirk Brenken (dev@brenken.org)
  5. # Please note: you have to install and configure the package 'mstmp' before using this script.
  6. # This is free software, licensed under the GNU General Public License v3.
  7. # You should have received a copy of the GNU General Public License
  8. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  9. LC_ALL=C
  10. PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  11. mail_ver="1.0.1"
  12. mail_daemon="$(command -v msmtp)"
  13. mail_profile="adb_notify"
  14. mail_debug="--debug"
  15. mail_rc=1
  16. if [ ! -x "${mail_daemon}" ]
  17. then
  18. mail_daemon="$(command -v sendmail)"
  19. fi
  20. if [ -f "/var/log/messages" ]
  21. then
  22. logfile="$(cat /var/log/messages | grep "adblock-")"
  23. else
  24. logfile="$(logread -e "adblock-")"
  25. fi
  26. # mail header
  27. #
  28. mail_sender="no-reply@adblock"
  29. mail_receiver="!!!ChangeMe!!!"
  30. mail_topic="adblock notification"
  31. mail_head="From: ${mail_sender}\nTo: ${mail_receiver}\nSubject: ${mail_topic}\nReply-to: ${mail_sender}\n\n"
  32. # mail body
  33. #
  34. mail_text="adblock status, generated at $(date 2>&1)!"
  35. mail_text="${mail_text}\n++\n++ System Information ++\n++\n$(cat /etc/banner 2>&1)"
  36. mail_text="${mail_text}\n\n++\n++ Adblock Information ++\n++\n$(/etc/init.d/adblock status 2>&1)"
  37. mail_text="${mail_text}\n\n++\n++ Logfile Information ++\n++\n${logfile}\n++\n++\n"
  38. # send mail
  39. #
  40. if [ -x "${mail_daemon}" ]
  41. then
  42. printf "%b" "${mail_head}${mail_text}" 2>/dev/null | "${mail_daemon}" ${mail_debug} -a "${mail_profile}" "${mail_receiver}" >/dev/null 2>&1
  43. mail_rc=${?}
  44. logger -p "info" -t "adblock-notify-[${mail_ver}]" "mail sent to '${mail_receiver}' with rc '${mail_rc}'"
  45. else
  46. logger -p "err" -t "adblock-notify-[${mail_ver}]" "msmtp mail daemon not found"
  47. fi
  48. exit ${mail_rc}