Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash
- # ==============================================================================
- # Get general information
- # ==============================================================================
- # Get hostname
- HOSTNAME=`hostname` 2> /dev/null
- # Get distro
- if [ -f "/etc/system-release" ]; then
- DISTRO=`cat /etc/system-release`
- else
- DISTRO=`python -c 'import platform; print platform.linux_distribution()[0] + " " + platform.linux_distribution()[1]'` 2> /dev/null
- fi
- # Get IP addresses
- IP=`ifconfig | awk -F "[: ]+" '/inet addr:/ { if ($4 != "127.0.0.1") print $4 }'` 2> /dev/null
- # ips is empty, let's try and get ip addresses with python instead
- if [ -z "${ips}" ]; then
- IP=`python -c 'import socket; print socket.gethostbyname(socket.gethostname())'` 2> /dev/null
- fi
- # Get uptime
- if [ -f "/proc/uptime" ]; then
- UPTIME=`cat /proc/uptime`
- UPTIME=${UPTIME%%.*}
- seconds=$(( UPTIME%60 ))
- minutes=$(( UPTIME/60%60 ))
- hours=$(( UPTIME/60/60%24 ))
- days=$(( UPTIME/60/60/24 ))
- UPTIME="$days"d", $hours"h", $minutes"m", $seconds"s""
- else
- UPTIME=""
- fi
- # ==============================================================================
- # Get CPU informaiton
- # ==============================================================================
- CPU_MODEL_NAME=""
- CPU_ARCHITECTURE=""
- if [ -f "/proc/cpuinfo" ]; then
- CPU_MODEL_NAME=`cat /proc/cpuinfo | grep 'model name' | uniq | cut -f 2 -d ":" | xargs`
- fi
- # Get architecture
- CPU_ARCHITECTURE=`lscpu | grep 'Architecture:' | uniq | cut -f 2 -d ":" | xargs`
- # Get cores
- CPU_CORES=`lscpu | grep 'Core(s) per socket:' | uniq | cut -f 2 -d ":" | xargs`
- # Get byte order
- CPU_BYTE_ORDER=`lscpu | grep 'Byte Order' -m 1 | uniq | cut -f 2 -d ":" | xargs`
- # Get load averages
- LOAD_AVG=`uptime | awk -F'load average:' '{ print $2 }' | xargs` 2> /dev/null
- # ==============================================================================
- # Output summary
- # ==============================================================================
- echo -n '{
- "distro": "'$DISTRO'",
- "ips": "'$IP'",
- "hostname": "' $HOSTNAME '",
- "uptime": "'$UPTIME'",
- "loadavg": "'$LOAD_AVG'",
- "cpu": {
- "model_name": "'$CPU_MODEL_NAME'",
- "architecture": "'$CPU_ARCHITECTURE'",
- "cores": "'$CPU_CORES'",
- "byte_order": "'$CPU_BYTE_ORDER'"
- }
- }
- '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement