#!/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" total=$(free -h | awk '/^Mem/ {print $2}') used=$(free -h | awk '/^Mem/ {print $3}') free=$(free -h | awk '/^Mem/ {print $4}') echo "Total: $total, Used: $used, Free: $free" } function diskinfo() { echo "Disk:" # We will get to this later disks=$(lsblk -d -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL | awk 'NR>1 {print $1,$2,$3,$4,$5}') for disk in $disks; do echo "$disk" done } function networkinfo() { echo "Network:" # get network interfaces and usage net=$(ifstat -j | jq -r '.[] | "\(.interface) TX:\(.tx.kbps) RX:\(.rx.kbps)"') for interface in $net; do echo "$interface" done } # This seems to be a good layout for sys.bash for now cpuinfo meminfo diskinfo networkinfo