logs.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Counting
  49. # Setting up variables
  50. scriptcount="0" ; consolecount="0" ; gamecount="0" ; srcdscount="0" ; smcount="0" ; ulxcount="0" ; darkrpcount="0"
  51. # Retrocompatibility, for logs directly in /log folder
  52. # Count how many script logfiles will be removed
  53. if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then
  54. gamecount=$(find "${gamelogdir}"/ -type f -mtime +${logdays}|wc -l)
  55. fi
  56. # Count how many script logfiles will be removed
  57. scriptcount=$(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l)
  58. echo "${consolelog}"
  59. # Count how many console logfiles will be removed, if those logs exist
  60. if [ -n "${consolelog}" ]; then
  61. consolecount=$(find "${consolelogdir}"/ -type f -mtime +${logdays}|wc -l)
  62. fi
  63. # Count total amount of files to remove
  64. count=$((${scriptcount} + ${consolecount} + ${gamecount} + ${srcdscount} + ${smcount} + ${ulxcount} + ${darkrpcount}))
  65. # Removing logfiles
  66. if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then
  67. find "${gamelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  68. fi
  69. find "${scriptlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  70. if [ -n "${consolelog}" ]; then
  71. find "${consolelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \;
  72. fi
  73. fn_printok "Removed ${count} log files"
  74. fn_scriptlog "Removed ${count} log files"
  75. sleep 1
  76. echo -en "\n"
  77. fi