fn_distrodetails 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # LGSM fn_distrodetails function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 141214
  6. # Description: Variables providing useful info on the Operating System such as disk and performace info.
  7. # Used for fn_details, fn_debugserver and fn_emailnotification.
  8. ## Distro infomation
  9. # Returns architecture, kernel and distro/os.
  10. arch=$(uname -m)
  11. kernel=$(uname -r)
  12. if [ -f /etc/lsb-release ]; then
  13. os=$(lsb_release -s -d)
  14. elif [ -f /etc/debian_version ]; then
  15. os="Debian $(cat /etc/debian_version)"
  16. elif [ -f /etc/redhat-release ]; then
  17. os=$(cat /etc/redhat-release)
  18. else
  19. os="$(uname -s) $(uname -r)"
  20. fi
  21. # Glibc version number
  22. # e.g: 1.17
  23. glibcv=$(ldd --version |grep ldd|awk '{print $NF}')
  24. # tmux version
  25. # e.g: tmux 1.6
  26. if [ -z $(command -v tmux) ]; then
  27. tmuxv="\e[0;31mNOT INSTALLED!\e[0m"
  28. elif [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd [:digit:]|tail -c 3)" -lt "16" ]; then
  29. tmuxv="$(tmux -V) (>= 1.6 required for console log)"
  30. else
  31. tmuxv=$(tmux -V)
  32. fi
  33. ## Performance
  34. # Average server load
  35. load=$(uptime|awk -F 'load average: ' '{ print $2 }')
  36. # Memory
  37. # Older versions of free do not support -h option.
  38. if [ "$(free -h > /dev/null 2>&1; echo $?)" -ne "0" ]; then
  39. option="-m"
  40. else
  41. option="-h"
  42. fi
  43. physmemtotal=$(free ${option} | awk '/Mem:/ {print $2}')
  44. physmemused=$(free ${option} | awk '/Mem:/ {print $3}')
  45. physmemfree=$(free ${option} | awk '/Mem:/ {print $4}')
  46. swaptotal=$(free ${option} | | awk '/Swap:/ {print $2}')
  47. swapused=$(free ${option} | awk '/Swap:/ {print $3}')
  48. swapfree=$(free ${option} | awk '/Swap:/ {print $4}')
  49. # Uptime
  50. uptime=$(</proc/uptime)
  51. uptime=${uptime%%.*}
  52. minutes=$(( uptime/60%60 ))
  53. hours=$(( uptime/60/60%24 ))
  54. days=$(( uptime/60/60/24 ))
  55. # Disk usage
  56. # available space on the partition.
  57. availspace=$(df -hP ${rootdir} | grep -v "Filesystem" | awk '{print $4}')
  58. # used space in serverfiles dir.
  59. serverfilesdu=$(du -sh ${serverfiles} | awk '{print $1}')
  60. if [ -z ${serverfilesdu} ]; then
  61. serverfilesdu="0M"
  62. fi
  63. # Backup info
  64. if [ -d "${backupdir}" ]; then
  65. # used space in backups dir.
  66. backupdirdu=$(du -sh ${backupdir} | awk '{print $1}')
  67. if [ -z ${backupdirdu} ]; then
  68. backupdirdu="0M"
  69. fi
  70. # number of backups.
  71. backupcount=$(find "${backupdir}"/*.tar.gz | wc -l)
  72. # most recent backup.
  73. lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1)
  74. # date of most recent backup.
  75. lastbackupdate=$(date -r ${lastbackup})
  76. # size of most recent backup.
  77. lastbackupsize=$(du -h "${lastbackup}" | awk '{print $1}')
  78. fi