logs.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # LGSM logs.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="100215"
  6. # Description: Acts as a log rotater, removing old logs.
  7. local modulename="Log Manager"
  8. # Check if logfile variable and file exist, create logfile if it doesn't exist
  9. if [ -n "${consolelog}" ]; then
  10. if [ ! -e "${consolelog}" ]; then
  11. touch "${consolelog}"
  12. fi
  13. fi
  14. # Log manager will start the cleanup if it finds logs older than ${logdays}
  15. if [ $(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l) -ne "0" ]; then
  16. fn_printdots "Starting"
  17. # Set addon logs directories
  18. sourcemodlogdir="${systemdir}/addons/sourcemod/logs"
  19. ulxlogdir="${systemdir}/data/ulx_logs"
  20. darkrplogdir="${systemdir}/data/darkrp_logs"
  21. # Setting up counting variables
  22. scriptcount="0" ; consolecount="0" ; gamecount="0" ; srcdscount="0" ; smcount="0" ; ulxcount="0" ; darkrpcount="0"
  23. sleep 1
  24. fn_printok "Starting"
  25. fn_scriptlog "Starting"
  26. sleep 1
  27. echo -en "\n"
  28. fn_printinfo "Removing logs older than ${logdays} days"
  29. fn_scriptlog "Removing logs older than ${logdays} days"
  30. sleep 1
  31. echo -en "\n"
  32. # Logging logfiles to be removed according to ${logdays}, counting and removing them
  33. # Script logfiles
  34. find "${scriptlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  35. scriptcount=$(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l)
  36. find "${scriptlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  37. # SRCDS and unreal logfiles
  38. if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then
  39. find "${gamelogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  40. gamecount=$(find "${gamelogdir}"/ -type f -mtime +${logdays}|wc -l)
  41. find "${gamelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  42. fi
  43. # Console logfiles
  44. if [ -n "${consolelog}" ]; then
  45. find "${consolelogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  46. consolecount=$(find "${consolelogdir}"/ -type f -mtime +${logdays}|wc -l)
  47. find "${consolelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  48. fi
  49. # Source addons logfiles
  50. if [ "${engine}" == "source" ]; then
  51. # SourceMod logfiles
  52. if [ -d "${sourcemodlogdir}" ]; then
  53. find "${sourcemodlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  54. smcount=$(find "${sourcemodlogdir}"/ -type f -mtime +${logdays}|wc -l)
  55. find "${sourcemodlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  56. fi
  57. # Garry's Mod logfiles
  58. if [ "${gamename}" == "Garry's Mod" ]; then
  59. # ULX logfiles
  60. if [ -d "${ulxlogdir}" ]; then
  61. find "${ulxlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  62. ulxcount=$(find "${ulxlogdir}"/ -type f -mtime +${logdays}|wc -l)
  63. find "${ulxlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  64. fi
  65. # DarkRP logfiles
  66. if [ -d "${darkrplogdir}" ]; then
  67. find "${darkrplogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  68. darkrpcount=$(find "${darkrplogdir}"/ -type f -mtime +${logdays}|wc -l)
  69. find "${darkrplogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  70. fi
  71. fi
  72. fi
  73. # Count total amount of files removed
  74. count=$((${scriptcount} + ${consolecount} + ${gamecount} + ${srcdscount} + ${smcount} + ${ulxcount} + ${darkrpcount}))
  75. # Job done
  76. fn_printok "Removed ${count} log files"
  77. fn_scriptlog "Removed ${count} log files"
  78. sleep 1
  79. echo -en "\n"
  80. fi