Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #!/usr/bin/bash
  2.  
  3. # ==============================================================================
  4. # Get general information
  5. # ==============================================================================
  6.  
  7. # Get hostname
  8. HOSTNAME=`hostname` 2> /dev/null
  9.  
  10. # Get distro
  11. if [ -f "/etc/system-release" ]; then
  12. DISTRO=`cat /etc/system-release`
  13. else
  14. DISTRO=`python -c 'import platform; print platform.linux_distribution()[0] + " " + platform.linux_distribution()[1]'` 2> /dev/null
  15. fi
  16.  
  17. # Get IP addresses
  18. IP=`ifconfig | awk -F "[: ]+" '/inet addr:/ { if ($4 != "127.0.0.1") print $4 }'` 2> /dev/null
  19.  
  20. # ips is empty, let's try and get ip addresses with python instead
  21. if [ -z "${ips}" ]; then
  22. IP=`python -c 'import socket; print socket.gethostbyname(socket.gethostname())'` 2> /dev/null
  23. fi
  24.  
  25. # Get uptime
  26. if [ -f "/proc/uptime" ]; then
  27. UPTIME=`cat /proc/uptime`
  28. UPTIME=${UPTIME%%.*}
  29. seconds=$(( UPTIME%60 ))
  30. minutes=$(( UPTIME/60%60 ))
  31. hours=$(( UPTIME/60/60%24 ))
  32. days=$(( UPTIME/60/60/24 ))
  33. UPTIME="$days"d", $hours"h", $minutes"m", $seconds"s""
  34. else
  35. UPTIME=""
  36. fi
  37.  
  38. # ==============================================================================
  39. # Get CPU informaiton
  40. # ==============================================================================
  41.  
  42. CPU_MODEL_NAME=""
  43. CPU_ARCHITECTURE=""
  44.  
  45. if [ -f "/proc/cpuinfo" ]; then
  46. CPU_MODEL_NAME=`cat /proc/cpuinfo | grep 'model name' | uniq | cut -f 2 -d ":" | xargs`
  47. fi
  48.  
  49. # Get architecture
  50. CPU_ARCHITECTURE=`lscpu | grep 'Architecture:' | uniq | cut -f 2 -d ":" | xargs`
  51.  
  52. # Get cores
  53. CPU_CORES=`lscpu | grep 'Core(s) per socket:' | uniq | cut -f 2 -d ":" | xargs`
  54.  
  55. # Get byte order
  56. CPU_BYTE_ORDER=`lscpu | grep 'Byte Order' -m 1 | uniq | cut -f 2 -d ":" | xargs`
  57.  
  58. # Get load averages
  59. LOAD_AVG=`uptime | awk -F'load average:' '{ print $2 }' | xargs` 2> /dev/null
  60.  
  61. # ==============================================================================
  62. # Output summary
  63. # ==============================================================================
  64.  
  65. echo -n '{
  66. "distro": "'$DISTRO'",
  67. "ips": "'$IP'",
  68. "hostname": "' $HOSTNAME '",
  69. "uptime": "'$UPTIME'",
  70. "loadavg": "'$LOAD_AVG'",
  71. "cpu": {
  72. "model_name": "'$CPU_MODEL_NAME'",
  73. "architecture": "'$CPU_ARCHITECTURE'",
  74. "cores": "'$CPU_CORES'",
  75. "byte_order": "'$CPU_BYTE_ORDER'"
  76. }
  77. }
  78. '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement