info_distro.sh 3.3 KB

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