alert_email.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # LinuxGSM alert_email.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Sends email alert.
  6. local commandname="ALERT"
  7. local commandaction="Alert"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_details_gameserver(){
  10. #
  11. # Quake Live Server Details
  12. # =====================================
  13. # Server name: ql-server
  14. # Server IP: 1.2.3.4:27960
  15. # RCON password: CHANGE_ME
  16. # Server password: NOT SET
  17. # Maxplayers: 16
  18. # Status: OFFLINE
  19. {
  20. echo -e ""
  21. echo -e "${gamename} Server Details"
  22. echo -e "================================="
  23. # Server name
  24. echo -e "Server name: ${servername}"
  25. # Server ip
  26. echo -e "Server IP: ${ip}:${port}"
  27. # Server password
  28. if [ -n "${serverpassword}" ]; then
  29. echo -e "Server password: ********"
  30. fi
  31. # RCON password
  32. if [ -n "${rconpassword}" ]; then
  33. echo -e "RCON password: ********"
  34. fi
  35. # Admin password
  36. if [ -n "${adminpassword}" ]; then
  37. echo -e "Admin password: ********"
  38. fi
  39. # Stats password (Quake Live)
  40. if [ -n "${statspassword}" ]; then
  41. echo -e "Stats password: ********"
  42. fi
  43. # Maxplayers
  44. if [ -n "${maxplayers}" ]; then
  45. echo -e "Maxplayers: ${maxplayers}"
  46. fi
  47. # Game mode
  48. if [ -n "${gamemode}" ]; then
  49. echo -e "Game mode: ${gamemode}"
  50. fi
  51. # Game world
  52. if [ -n "${gameworld}" ]; then
  53. echo -e "Game world: ${gameworld}"
  54. fi
  55. # Tick rate
  56. if [ -n "${tickrate}" ]; then
  57. echo -e "Tick rate: ${tickrate}"
  58. fi
  59. # TeamSpeak dbplugin
  60. if [ -n "${dbplugin}" ]; then
  61. echo -e "dbplugin: ${dbplugin}"
  62. fi
  63. # Online status
  64. if [ "${status}" == "0" ]; then
  65. echo -e "Status: OFFLINE"
  66. else
  67. echo -e "Status: ONLINE"
  68. fi
  69. } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${emaillog}" > /dev/null 2>&1
  70. }
  71. fn_print_dots "Sending Email alert: ${email}"
  72. sleep 0.5
  73. fn_script_log_info "Sending Email alert: ${email}"
  74. info_distro.sh
  75. info_config.sh
  76. info_glibc.sh
  77. info_messages.sh
  78. if [ -f "${emaillog}" ]; then
  79. rm "${emaillog}"
  80. fi
  81. {
  82. fn_info_message_head
  83. fn_info_message_distro
  84. fn_info_message_performance
  85. fn_info_message_disk
  86. fn_info_message_gameserver
  87. fn_info_logs
  88. } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${emaillog}" > /dev/null 2>&1
  89. if [ -n "${emailfrom}" ]; then
  90. mail -s "${alertsubject}" -r "${emailfrom}" "${email}" < "${emaillog}"
  91. else
  92. mail -s "${alertsubject}" "${email}" < "${emaillog}"
  93. fi
  94. exitcode=$?
  95. if [ "${exitcode}" == "0" ]; then
  96. fn_print_ok_nl "Sending Email alert: ${email}"
  97. fn_script_log_pass "Sending Email alert: ${email}"
  98. else
  99. fn_print_fail_nl "Sending Email alert: ${email}"
  100. fn_script_log_fatal "Sending Email alert: ${email}"
  101. fi