logs.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. # Set source log directory
  15. if [ -z "${systemdir}" && "${engine}" == "source" ]; then
  16. srcdslogdir="${systemdir}/logs"
  17. # Set addons directories
  18. sourcemodlogdir="${systemdir}/addons/sourcemod/logs"
  19. # Set gmod addons directories
  20. if [ "${gamename}" == "Garry's Mod" ]; then
  21. ulxlogdir="${systemdir}/data/ulx_logs"
  22. darkrplogdir="${systemdir}/data/darkrp_logs"
  23. fi
  24. fi
  25. # log manager will active if finds logs older than ${logdays}
  26. if [ $(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l) -ne "0" ]; then
  27. fn_printdots "Starting"
  28. sleep 1
  29. fn_printok "Starting"
  30. fn_scriptlog "Starting"
  31. sleep 1
  32. echo -en "\n"
  33. fn_printinfo "Removing logs older than ${logdays} days"
  34. fn_scriptlog "Removing logs older than ${logdays} days"
  35. sleep 1
  36. echo -en "\n"
  37. # Retrocompatibility, for logs directly in /log folder
  38. # Find game logfiles older than ${logdays} and write that list to the current script log
  39. if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then
  40. find "${gamelogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  41. fi
  42. # Find script logfiles older than ${logdays} and write that list to the current script log
  43. find "${scriptlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  44. # Find console logfiles older than ${logdays} and write that list to the current script log
  45. if [ -n "${consolelog}" ]; then
  46. find "${consolelogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}"
  47. fi
  48. # Retrocompatibility, for logs directly in /log folder
  49. # Count how many script logfiles will be removed
  50. if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then
  51. gamecount=$(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l)
  52. fi
  53. # Count how many script logfiles will be removed
  54. scriptcount=$(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l)
  55. echo "${consolelog}"
  56. # Count how many console logfiles will be removed
  57. if [ -n "${consolelog}" ]; then
  58. consolecount=$(find "${consolelogdir}"/ -type f -mtime +${logdays}|wc -l)
  59. else
  60. consolecount=0
  61. fi
  62. # Count total amount of files to remove
  63. count=$((${scriptcount} + ${consolecount}))
  64. if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then
  65. count=$((${scriptcount} + ${consolecount} + ${gamecount}))
  66. else
  67. count=$((${scriptcount} + ${consolecount}))
  68. fi
  69. # Removing logfiles
  70. if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then
  71. find "${gamelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  72. fi
  73. find "${scriptlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  74. if [ -n "${consolelog}" ]; then
  75. find "${consolelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  76. fi
  77. fn_printok "Removed ${count} log files"
  78. fn_scriptlog "Removed ${count} log files"
  79. sleep 1
  80. echo -en "\n"
  81. fi