#!/bin/sh # # qsi(.sh) -- Prints a Quick System Information summary about the system's # OS distribution, CPU, memory, kernel, filesystem(s), and network. # # http://www.haganfox.net/Main/QuickSystemInfo ## Settings # ## $SHOWFS determines if the Filesystem section will appear. ## 1 means show it, 0 means leave it out. SHOWFS=1 # ## $FSMOUNTS is a comma-separated whitelist of filesystems ## that may be mounted on devices in /dev/ . FSMOUNTS='/,/boot,/home,/opt,/root,/usr,/usr/local,/tmp,/var,/storage' # Title DATE=$(date "+%F %H:%M %Z") HOSTNAME=$(hostname) # Distribution if test -f /etc/lsb-release; then DIST=$(grep DESCRIPTION /etc/lsb-release | awk -F'=' '{print $NF}' | tr -d \") elif test -f /etc/os-release; then D1=$(grep ^NAME\= /etc/os-release | awk -F'=' '{print $NF}' | tr -d \") if grep ^VERSION\= /etc/os-release >/dev/null; then # version if available D2=" $(grep ^VERSION\= /etc/os-release | awk -F'=' '{print $NF}' | tr -d \")" fi DIST="$D1$D2" else DIST=$(cat /proc/version \ | awk -F')' '{print $(NF-2)}' \ | awk -F'(' '{print $NF}') fi if test -f /etc/os-release; then # sometimes ID shows "derived from" DISTID="$(grep ^ID\= /etc/os-release | awk -F'=' '{print $NF}') " fi DISTDATE=$(find /etc -type d 2>/dev/null \ | xargs ls -d --full-time 2>/dev/null \ | awk '{print $6}' \ | awk -F'-' '{print $1"-"$2}' \ | sort \ | uniq -c \ | sort -n \ | awk 'END{print $2}') # CPU CPUCOUNT=$(grep "^physical id" /proc/cpuinfo | sort -u | wc -l ) if test $CPUCOUNT -gt 1; then # multiple CPUs? CPUS="s"; else CPUS=" "; fi CPUMODEL=$(grep '^model name' /proc/cpuinfo \ | awk -F': ' 'NR==1{print $NF}' \ | tr -s " ") ACORECOUNT=$(grep "^core id" /proc/cpuinfo | sort -u | wc -l) LCORECOUNT=$(grep -c '^processor' /proc/cpuinfo) if $(which lscpu >/dev/null 2>&1); then # has lscpu? CPUL2=$(lscpu | grep "^L2 cache" | awk '{print $NF}') else CPUL2="unknown" fi # Memory if free -h >/dev/null 2>&1; then # support -h? dh=-h; fi RAM=$(free $dh | grep Mem | awk '{print $2}') RAMF=$(free $dh | grep Mem | awk '{print $4}') SWAP=$(free $dh | grep Swap | awk '{print $2}') SWAPF=$(free $dh | grep Swap | awk '{print $4}') # Kernel if test -x /bin/uname >/dev/null; then # can use uname? KERNEL=$(uname -srm) KVER=$(uname -v) elif $(which php >/dev/null); then # try PHP KNAME=$(php -r "echo php_uname('s');") KREV=$(php -r "echo php_uname('r');") KHW=$(php -r "echo php_uname('m');") KERNEL="$KNAME $KREV $KHW" KVER=$(php -r "echo php_uname('v');") else KERNEL="unknown kernel name" KVER="unknown kernel version" fi # Filesystem if test "$1" = "-f"; then SHOWFS=0; fi # -f parameter hides if test "$1" = "+f"; then SHOWFS=1; fi # +f parameter shows if test $SHOWFS = 1; then devmounts=$(df 2>/dev/null | grep '^/dev/'[A-Za-z] | sort | awk '{print $6}') n=1 for mount in $devmounts; do IFS="," # field separator for FSM in $FSMOUNTS; do if test x$mount = x$FSM; then # has a device FSN=$(df $FSM | awk 'NR==2{print $1}') # filesystem FSS=$(df -h $FSM | awk 'NR==2{print $2}') # size FST=$(df -T $FSM | awk 'NR==2{print $2}') # type FSA=$(df -h $FSM | awk 'NR==2{print $4}') # avail if test $n -gt 1; then FSL=" $sp" fi FS="$FS$(printf %b \ "$FSL $FSN is $FSS $FST, with $FSA available on $FSM") " sp=" " n=$(expr $n + 1) fi done done if test $n -eq 1; then # no mounts FSL="Filesystem: No mounts were found. (Live-boot?) " elif test $n -eq 2; then # one mount FSL="Filesystem:" else # multiple mounts FSL="Filesystems:" fi fi # Network if ! echo :$PATH: | grep -q ":/sbin:"; then # $PATH has /sbin? PATH=$PATH:/sbin; fi IFCOUNT=$(ip -o link show | wc -l) IFNAMES=$(ip -o link show | awk -F':' '{print $2}' | paste -s -d, -) GW=$(ip route get 8.8.8.8 | awk 'NR==1{print $3}') if ip addr | grep -q 'state UP'; then # is "state UP" shown? MASK="/$(ip addr \ | grep -A2 'state UP' \ | awk 'END{print $2}' \ | awk -F'/' '{print $2}')" fi GWNIC=$(ip route get 8.8.8.8 | awk 'NR==1{print $5}') IPADDR=$(ip route get 8.8.8.8 | awk 'NR==1{print $7}') # Output cat << EOT === $DATE System Information for $HOSTNAME === Distribution: $DIST ($DISTID$DISTDATE) $CPUCOUNT CPU$CPUS: $CPUMODEL $ACORECOUNT cores, $LCORECOUNT logical cores, $CPUL2 cache Memory: $RAM RAM + $SWAP swap, with $RAMF + $SWAPF free Kernel: $KERNEL $KVER $FSL$FS$IFCOUNT network interfaces:$IFNAMES EOT if test x = x$GW; then echo "There is no gateway address." else echo "Gateway is $GW$MASK via $GWNIC with IP $IPADDR" fi