fn_emailnotification 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. # LGSM fn_emailnotification function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 011214
  6. fn_distro
  7. fn_uptime
  8. fn_load
  9. {
  10. echo -e "========================================\n${servicename} details\n========================================\n"
  11. echo -e "Service: ${servicename}"
  12. echo -e "Server: ${servername}"
  13. echo -e "Game: ${gamename}"
  14. echo -e "Failure reason: ${failurereason}"
  15. echo -e "Action Taken: ${actiontaken}\n"
  16. echo -e "========================================\nServer details\n========================================\n"
  17. echo -e "Date: $(date)"
  18. echo -e "Distro: ${os}"
  19. echo -e "Arch: ${arch}"
  20. echo -e "Kernel: ${kernel}"
  21. echo -e "Hostname: $HOSTNAME"
  22. echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m"
  23. echo -e "Avg Load${load}\n"
  24. echo -e "========================================\nLogs\n========================================\n"
  25. echo -e "Script log\n===================\n"
  26. }|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
  27. tail -25 "${scriptlog}" >> "${emaillog}"
  28. if [ ! -z "${consolelog}" ]; then
  29. echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
  30. tail -25 "${consolelog}" >> "${emaillog}"
  31. fi
  32. if [ ! -z "${gamelogdir}" ]; then
  33. echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
  34. tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
  35. fi
  36. mail -s "${subject}" ${email} < "${emaillog}"
  37. fn_printinfo "Sent email notification to ${email}"
  38. fn_scriptlog "Sent email notification to ${email}"
  39. sleep 1
  40. echo -en "\n"