#!/bin/bash #set -x # a bash file that can provide various bits of info about the system function cpuinfo() { # now lets extract the number of core and the architecture num_cores=$(lscpu | grep -E "^CPU\(s\):" | awk '{print $2}') architecture=$(lscpu | grep -E "^Architecture:" | awk '{print $2}') # get cpu usage cpu_usage=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}') echo "$num_cores cores, $architecture architecture, CPU usage: $cpu_usage" } function meminfo() { echo "Memory:" # We will get to this later #total=$(free -h| grep ) #| grep -E "Mem|Swap" } function diskinfo() { echo "Disk:" # We will get to this later } function networkinfo() { echo "Network:" # get network interfaces and usage # get network adapters and usage adapters=$(ip -s addr | grep -E '^[0-9]:' | awk -F ':' '{print $2}') for adapter in $adapters; do rx=$(ip -s link show $adapter | awk '/RX:/ {print $2}') tx=$(ip -s link show $adapter | awk '/TX:/ {print $2}') echo -e "$adapter\tRX: $rx\tTX: $tx" done } # This seems to be a good layout for sys.bash for now cpuinfo meminfo diskinfo networkinfo