fn_distrodetails 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd [:digit:]|tail -c 3)" -lt "16" ]; then
  27. tmuxv="$(tmux -V) (>= 1.6 required for console log)"
  28. else
  29. tmuxv=$(tmux -V)
  30. fi
  31. ## Performance
  32. # Average server load
  33. load=$(uptime|awk -F 'load average: ' '{ print $2 }')
  34. # Memory
  35. # Older versions of free do not support -h option.
  36. if [ "$(free -h > /dev/null 2>&1; echo $?)" -ne "0" ]; then
  37. option="-m"
  38. else
  39. option="-h"
  40. fi
  41. physmemtotal=$(free ${option} | grep "Mem:" | awk '{print $2}')
  42. physmemused=$(free ${option} | grep "Mem:" | awk '{print $3}')
  43. physmemfree=$(free ${option} | grep "Mem:" | awk '{print $4}')
  44. swaptotal=$(free ${option} | grep "Swap:" | awk '{print $2}')
  45. swapused=$(free ${option} | grep "Swap:" | awk '{print $3}')
  46. swapfree=$(free ${option} | grep "Swap:" | awk '{print $4}')
  47. # Uptime
  48. uptime=$(</proc/uptime)
  49. uptime=${uptime%%.*}
  50. minutes=$(( uptime/60%60 ))
  51. hours=$(( uptime/60/60%24 ))
  52. days=$(( uptime/60/60/24 ))
  53. # Disk usage
  54. # available space on the partition.
  55. availspace=$(df -hP ${rootdir} | grep -v "Filesystem" | awk '{print $4}')
  56. # used space in serverfiles dir.
  57. serverfilesdu=$(du -sh ${serverfiles} | awk '{print $1}')
  58. if [ -z ${serverfilesdu} ]; then
  59. serverfilesdu="0M"
  60. fi
  61. # Backup info
  62. if [ -d "${backupdir}" ]; then
  63. # used space in backups dir.
  64. backupdirdu=$(du -sh ${backupdir} | awk '{print $1}')
  65. if [ -z ${backupdirdu} ]; then
  66. backupdirdu="0M"
  67. fi
  68. # number of backups.
  69. backupcount=$(find "${backupdir}"/*.tar.gz | wc -l)
  70. # most recent backup.
  71. lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1)
  72. # date of most recent backup.
  73. lastbackupdate=$(date -r ${lastbackup})
  74. # size of most recent backup.
  75. lastbackupsize=$(du -h "${lastbackup}" | awk '{print $1}')
  76. fi