4
0

core_logs.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # LinuxGSM core_logs.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Acts as a log rotator, removing old logs.
  7. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. # Check if logfile variable and file exist, create logfile if it doesn't exist.
  9. if [ "${consolelog}" ]; then
  10. if [ ! -f "${consolelog}" ]; then
  11. touch "${consolelog}"
  12. fi
  13. fi
  14. # For games not displaying a console, and having logs into their game directory.
  15. check_status.sh
  16. if [ "${status}" != "0" ] && [ "${commandname}" == "START" ] && [ -n "${gamelogfile}" ]; then
  17. if [ "$(find "${systemdir}" -name "gamelog*.log")" ]; then
  18. fn_print_info "Moving game logs to ${gamelogdir}"
  19. fn_script_log_info "Moving game logs to ${gamelogdir}"
  20. echo -en "\n"
  21. fn_sleep_time
  22. mv "${systemdir}"/gamelog*.log "${gamelogdir}"
  23. fi
  24. fi
  25. # Log manager will start the cleanup if it finds logs older than "${logdays}".
  26. if [ "$(find "${lgsmlogdir}"/ -type f -mtime +"${logdays}" | wc -l)" -ne "0" ]; then
  27. fn_print_dots "Starting"
  28. # Set common logs directories
  29. commonlogs="${systemdir}/logs"
  30. commonsourcelogs="${systemdir}/*/logs"
  31. # Set addon logs directories
  32. sourcemodlogdir="${systemdir}/addons/sourcemod/logs"
  33. ulxlogdir="${systemdir}/data/ulx_logs"
  34. darkrplogdir="${systemdir}/data/darkrp_logs"
  35. legacyserverlogdir="${logdir}/server"
  36. # Setting up counting variables
  37. scriptcount="0"
  38. consolecount="0"
  39. gamecount="0"
  40. srcdscount="0"
  41. smcount="0"
  42. ulxcount="0"
  43. darkrpcount="0"
  44. legacycount="0"
  45. fn_sleep_time
  46. fn_print_info "Removing logs older than ${logdays} days"
  47. fn_script_log_info "Removing logs older than ${logdays} days"
  48. # Logging logfiles to be removed according to "${logdays}", counting and removing them.
  49. # Script logfiles.
  50. find "${lgsmlogdir}"/ -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  51. scriptcount=$(find "${lgsmlogdir}"/ -type f -mtime +"${logdays}" | wc -l)
  52. find "${lgsmlogdir}"/ -mtime +"${logdays}" -type f -exec rm -f {} \;
  53. # SRCDS and unreal logfiles.
  54. if [ "${engine}" == "unreal2" ] || [ "${engine}" == "source" ]; then
  55. find "${gamelogdir}"/ -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  56. gamecount=$(find "${gamelogdir}"/ -type f -mtime +"${logdays}" | wc -l)
  57. find "${gamelogdir}"/ -mtime +"${logdays}" -type f -exec rm -f {} \;
  58. fi
  59. # Console logfiles.
  60. if [ "${consolelog}" ]; then
  61. find "${consolelogdir}"/ -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  62. consolecount=$(find "${consolelogdir}"/ -type f -mtime +"${logdays}" | wc -l)
  63. find "${consolelogdir}"/ -mtime +"${logdays}" -type f -exec rm -f {} \;
  64. fi
  65. # Common logfiles.
  66. if [ -d "${commonlogs}" ]; then
  67. find "${commonlogs}"/ -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  68. smcount=$(find "${commonlogs}"/ -type f -mtime +"${logdays}" | wc -l)
  69. find "${commonlogs}"/ -mtime +"${logdays}" -type f -exec rm -f {} \;
  70. fi
  71. if [ -d "${commonsourcelogs}" ]; then
  72. find "${commonsourcelogs}"/* -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  73. smcount=$(find "${commonsourcelogs}"/* -type f -mtime +"${logdays}" | wc -l)
  74. find "${commonsourcelogs}"/* -mtime +"${logdays}" -type f -exec rm -f {} \;
  75. fi
  76. # Source addons logfiles.
  77. if [ "${engine}" == "source" ]; then
  78. # SourceMod logfiles.
  79. if [ -d "${sourcemodlogdir}" ]; then
  80. find "${sourcemodlogdir}"/ -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  81. smcount=$(find "${sourcemodlogdir}"/ -type f -mtime +"${logdays}" | wc -l)
  82. find "${sourcemodlogdir}"/ -mtime +"${logdays}" -type f -exec rm -f {} \;
  83. fi
  84. # Garry's Mod logfiles.
  85. if [ "${shortname}" == "gmod" ]; then
  86. # ULX logfiles.
  87. if [ -d "${ulxlogdir}" ]; then
  88. find "${ulxlogdir}"/ -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  89. ulxcount=$(find "${ulxlogdir}"/ -type f -mtime +"${logdays}" | wc -l)
  90. find "${ulxlogdir}"/ -mtime +"${logdays}" -type f -exec rm -f {} \;
  91. fi
  92. # DarkRP logfiles.
  93. if [ -d "${darkrplogdir}" ]; then
  94. find "${darkrplogdir}"/ -type f -mtime +"${logdays}" | tee >> "${lgsmlog}"
  95. darkrpcount=$(find "${darkrplogdir}"/ -type f -mtime +"${logdays}" | wc -l)
  96. find "${darkrplogdir}"/ -mtime +"${logdays}" -type f -exec rm -f {} \;
  97. fi
  98. fi
  99. fi
  100. # Count total amount of files removed.
  101. countlogs=$((scriptcount + consolecount + gamecount + srcdscount + smcount + ulxcount + darkrpcount))
  102. # Job done.
  103. fn_print_ok "Removed ${countlogs} log files"
  104. fn_script_log "Removed ${countlogs} log files"
  105. fi