info_distro.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. distroversion=$(grep VERSION_ID /etc/os-release | tr -cd '[:digit:]')
  25. ## Glibc version
  26. # e.g: 1.17
  27. glibcversion="$(ldd --version | sed -n '1s/.* //p')"
  28. ## tmux version
  29. # e.g: tmux 1.6
  30. if [ -z "$(command -v tmux)" ]; then
  31. tmuxv="${red}NOT INSTALLED!${default}"
  32. elif [ "$(tmux -V|sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')" -lt "16" ]; then
  33. tmuxv="$(tmux -V) (>= 1.6 required for console log)"
  34. else
  35. tmuxv=$(tmux -V)
  36. fi
  37. ## Uptime
  38. uptime=$(</proc/uptime)
  39. uptime=${uptime/[. ]*/}
  40. minutes=$(( uptime/60%60 ))
  41. hours=$(( uptime/60/60%24 ))
  42. days=$(( uptime/60/60/24 ))
  43. ### Performance infomation
  44. ## Average server load
  45. load=$(uptime|awk -F 'load average: ' '{ print $2 }')
  46. ## Memory Infomation
  47. # Available RAM and swap.
  48. # Older versions of free do not support -h option.
  49. if [ "$(free -h > /dev/null 2>&1; echo $?)" -ne "0" ]; then
  50. humanreadable="-m"
  51. else
  52. humanreadable="-h"
  53. fi
  54. physmemtotal=$(free ${humanreadable} | awk '/Mem:/ {print $2}')
  55. physmemtotalmb=$(free -m | awk '/Mem:/ {print $2}')
  56. physmemused=$(free ${humanreadable} | awk '/Mem:/ {print $3}')
  57. physmemfree=$(free ${humanreadable} | awk '/Mem:/ {print $4}')
  58. physmemcached=$(free ${humanreadable} | awk '/cache:/ {print $4}')
  59. swaptotal=$(free ${humanreadable} | awk '/Swap:/ {print $2}')
  60. swapused=$(free ${humanreadable} | awk '/Swap:/ {print $3}')
  61. swapfree=$(free ${humanreadable} | awk '/Swap:/ {print $4}')
  62. ### Disk Infomation
  63. ## Available disk space on the partition.
  64. filesystem=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $1}')
  65. totalspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $2}')
  66. usedspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $3}')
  67. availspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $4}')
  68. ## LGSM used space total.
  69. rootdirdu=$(du -sh "${rootdir}" 2> /dev/null | awk '{print $1}')
  70. if [ -z "${rootdirdu}" ]; then
  71. rootdirdu="0M"
  72. fi
  73. ## LGSM used space in serverfiles dir.
  74. filesdirdu=$(du -sh "${filesdir}" 2> /dev/null | awk '{print $1}')
  75. if [ -z "${filesdirdu}" ]; then
  76. filesdirdu="0M"
  77. fi
  78. ## LGSM used space total minus backup dir.
  79. rootdirduexbackup=$(du -sh --exclude="${backupdir}" "${filesdir}" 2> /dev/null | awk '{print $1}')
  80. if [ -z "${rootdirduexbackup}" ]; then
  81. rootdirduexbackup="0M"
  82. fi
  83. ## Backup info
  84. if [ -d "${backupdir}" ]; then
  85. # used space in backups dir.
  86. backupdirdu=$(du -sh "${backupdir}" | awk '{print $1}')
  87. if [ -z "${backupdirdu}" ]; then
  88. backupdirdu="0M"
  89. fi
  90. # number of backups.
  91. backupcount=$(find "${backupdir}"/*.tar.gz | wc -l)
  92. # most recent backup.
  93. lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1)
  94. # date of most recent backup.
  95. lastbackupdate=$(date -r "${lastbackup}")
  96. # size of most recent backup.
  97. lastbackupsize=$(du -h "${lastbackup}" | awk '{print $1}')
  98. fi