info_distro.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 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. physmemused=$(free ${humanreadable} | awk '/Mem:/ {print $3}')
  53. physmemfree=$(free ${humanreadable} | awk '/Mem:/ {print $4}')
  54. swaptotal=$(free ${humanreadable} | awk '/Swap:/ {print $2}')
  55. swapused=$(free ${humanreadable} | awk '/Swap:/ {print $3}')
  56. swapfree=$(free ${humanreadable} | awk '/Swap:/ {print $4}')
  57. ### Disk Infomation
  58. ## Available disk space on the partition.
  59. filesystem=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $1}')
  60. totalspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $2}')
  61. usedspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $3}')
  62. availspace=$(df -hP "${rootdir}" | grep -v "Filesystem" | awk '{print $4}')
  63. ## LGSM used space total.
  64. rootdirdu=$(du -sh "${rootdir}" 2> /dev/null | awk '{print $1}')
  65. if [ -z "${rootdirdu}" ]; then
  66. rootdirdu="0M"
  67. fi
  68. ## LGSM used space in serverfiles dir.
  69. filesdirdu=$(du -sh "${filesdir}" 2> /dev/null | awk '{print $1}')
  70. if [ -z "${filesdirdu}" ]; then
  71. filesdirdu="0M"
  72. fi
  73. ## LGSM used space total minus backup dir.
  74. rootdirduexbackup=$(du -sh --exclude="${backupdir}" "${filesdir}" 2> /dev/null | awk '{print $1}')
  75. if [ -z "${rootdirduexbackup}" ]; then
  76. rootdirduexbackup="0M"
  77. fi
  78. ## Backup info
  79. if [ -d "${backupdir}" ]; then
  80. # used space in backups dir.
  81. backupdirdu=$(du -sh "${backupdir}" | awk '{print $1}')
  82. if [ -z "${backupdirdu}" ]; then
  83. backupdirdu="0M"
  84. fi
  85. # number of backups.
  86. backupcount=$(find "${backupdir}"/*.tar.gz | wc -l)
  87. # most recent backup.
  88. lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1)
  89. # date of most recent backup.
  90. lastbackupdate=$(date -r "${lastbackup}")
  91. # size of most recent backup.
  92. lastbackupsize=$(du -h "${lastbackup}" | awk '{print $1}')
  93. fi