info_distro.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # LGSM info_distro.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Variables providing useful info on the Operating System such as disk and performace info.
  6. # Used for command_details.sh, command_debug.sh and alert.sh.
  7. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  8. ### Distro infomation
  9. ## Distro
  10. # Returns architecture, kernel and distro/os.
  11. arch=$(uname -m)
  12. kernel=$(uname -r)
  13. if [ -n "$(command -v lsb_release)" ]; then
  14. distroname=$(lsb_release -s -d)
  15. elif [ -f "/etc/os-release" ]; then
  16. distroname=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="')
  17. elif [ -f "/etc/debian_version" ]; then
  18. distroname="Debian $(cat /etc/debian_version)"
  19. elif [ -f "/etc/redhat-release" ]; then
  20. distroname=$(cat /etc/redhat-release)
  21. else
  22. distroname="$(uname -s) $(uname -r)"
  23. fi
  24. if [ -f "/etc/os-release" ]; then
  25. distroversion=$(grep VERSION_ID /etc/os-release | tr -cd '[:digit:]')
  26. elif [ -n "$(command -v yum)" ]; then
  27. distroversion=$(rpm -qa \*-release | grep -Ei "oracle|redhat|centos" | cut -d"-" -f3)
  28. fi
  29. ## Glibc version
  30. # e.g: 1.17
  31. glibcversion="$(ldd --version | sed -n '1s/.* //p')"
  32. ## tmux version
  33. # e.g: tmux 1.6
  34. if [ -z "$(command -v tmux)" ]; then
  35. tmuxv="${red}NOT INSTALLED!${default}"
  36. elif [ "$(tmux -V|sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')" -lt "16" ]; then
  37. tmuxv="$(tmux -V) (>= 1.6 required for console log)"
  38. else
  39. tmuxv=$(tmux -V)
  40. fi
  41. ## Uptime
  42. uptime=$(</proc/uptime)
  43. uptime=${uptime/[. ]*/}
  44. minutes=$(( uptime/60%60 ))
  45. hours=$(( uptime/60/60%24 ))
  46. days=$(( uptime/60/60/24 ))
  47. ### Performance infomation
  48. ## Average server load
  49. load=$(uptime|awk -F 'load average: ' '{ print $2 }')
  50. ## Memory Infomation
  51. # Available RAM and swap.
  52. # Older versions of free do not support -h option.
  53. if [ "$(free -h > /dev/null 2>&1; echo $?)" -ne "0" ]; then
  54. humanreadable="-m"
  55. else
  56. humanreadable="-h"
  57. fi
  58. physmemtotal=$(free ${humanreadable} | awk '/Mem:/ {print $2}')
  59. physmemtotalmb=$(free -m | awk '/Mem:/ {print $2}')
  60. physmemused=$(free ${humanreadable} | awk '/Mem:/ {print $3}')
  61. physmemfree=$(free ${humanreadable} | awk '/Mem:/ {print $4}')
  62. physmemcached=$(free ${humanreadable} | awk '/cache:/ {print $4}')
  63. swaptotal=$(free ${humanreadable} | awk '/Swap:/ {print $2}')
  64. swapused=$(free ${humanreadable} | awk '/Swap:/ {print $3}')
  65. swapfree=$(free ${humanreadable} | awk '/Swap:/ {print $4}')
  66. ### Disk Infomation
  67. ## Available disk space on the partition.
  68. filesystem=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $1}')
  69. totalspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $2}')
  70. usedspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $3}')
  71. availspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $4}')
  72. ## LGSM used space total.
  73. rootdirdu=$(du -sh "${rootdir}" 2> /dev/null | awk '{print $1}')
  74. if [ -z "${rootdirdu}" ]; then
  75. rootdirdu="0M"
  76. fi
  77. ## LGSM used space in serverfiles dir.
  78. filesdirdu=$(du -sh "${filesdir}" 2> /dev/null | awk '{print $1}')
  79. if [ -z "${filesdirdu}" ]; then
  80. filesdirdu="0M"
  81. fi
  82. ## LGSM used space total minus backup dir.
  83. rootdirduexbackup=$(du -sh --exclude="${backupdir}" "${filesdir}" 2> /dev/null | awk '{print $1}')
  84. if [ -z "${rootdirduexbackup}" ]; then
  85. rootdirduexbackup="0M"
  86. fi
  87. ## Backup info
  88. if [ -d "${backupdir}" ]; then
  89. # used space in backups dir.
  90. backupdirdu=$(du -sh "${backupdir}" | awk '{print $1}')
  91. if [ -z "${backupdirdu}" ]; then
  92. backupdirdu="0M"
  93. fi
  94. # number of backups.
  95. backupcount=$(find "${backupdir}"/*.tar.gz | wc -l)
  96. # most recent backup.
  97. lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1)
  98. # date of most recent backup.
  99. lastbackupdate=$(date -r "${lastbackup}")
  100. # size of most recent backup.
  101. lastbackupsize=$(du -h "${lastbackup}" | awk '{print $1}')
  102. fi