#!/bin/bash W="\e[0;39m" G="\e[1;32m" R="\e[1;31m" # get load averages IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(cat /proc/loadavg | awk '{ print $1,$2,$3 }') # get free memory IFS=" " read USED FREE TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$4,$2'}) # get processes PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'` PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'` PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}` PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'` # get processors PROCESSOR_NAME=`grep "model name" /proc/cpuinfo | cut -d ' ' -f3- | awk {'print $0'} | head -1` PROCESSOR_COUNT=`grep -ioP 'processor\t:' /proc/cpuinfo | wc -l` ## Adapted from https://github.com/mrlesmithjr/ansible-motd/blob/master/templates/etc/update-motd.d/30-sysinfo.j2 # Capture DNS Servers DNS_SERVER="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}' | tr '\r\n' ' ')" # Capture Interfaces NET_INTERFACES="$(ip link show | awk -F: '$1>0 {print $2}' | grep -v lo)" # Using captured interfaces loop through them and capture: # link state and ip address # Only if IP address is defined first="" NET_IPS="$(for int in ${NET_INTERFACES[@]}; do state="$(ip link show $int | awk '{print $9}')" ip_addr="$(ip -4 add show $int | grep inet | awk '{print $2}'| awk -F/ '{print $1}')" if [ ! -z $ip_addr ]; then echo -e "$W$first$int [$R$state$W]: $G$ip_addr" first=" " fi done )" echo -e " ${W}system info: $W Distro......: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'` $W Kernel......: $W`uname -sr` $W Uptime......: $W`uptime -p` $W Load........: $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m) $W Processes...: $W$G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user), $G$PROCESS_ALL$W (total) $W CPU.........: $W$PROCESSOR_NAME ($G$PROCESSOR_COUNT$W vCPU) $W Memory......: $G$USED$W used, $G$FREE$W free, $G$TOTAL$W total $W IP Addresses: $NET_IPS $W DNS Server..: $G$DNS_SERVER$W"