Skip to content

Instantly share code, notes, and snippets.

@principis
Last active June 8, 2023 09:41
Show Gist options
  • Save principis/303d3d326884eb50b0a0de19b2344b6a to your computer and use it in GitHub Desktop.
Save principis/303d3d326884eb50b0a0de19b2344b6a to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
FAILED=$(systemctl list-units --state=failed --no-legend --plain)
sensor="coretemp-isa-0000"
USER=$(whoami)
HOSTNAME=$(uname -n)
TEMPERATURE=$(sensors $sensor | awk 'NR==3{print $4}')
MEMORY1=$(free -t -m | grep "Mem" | awk '{print $3;}')
MEMORY2=$(free -t -m | grep "Mem" | awk '{print $2 " MB";}')
PSA=$(ps -Afl | wc -l)
#System uptime
uptime=$(cut </proc/uptime -f1 -d.)
upDays=$((uptime / 60 / 60 / 24))
upHours=$((uptime / 60 / 60 % 24))
upMins=$((uptime / 60 % 60))
upSecs=$((uptime % 60))
#System load
LOAD=$(awk '{print $1", "$2", "$3}' /proc/loadavg)
IP_BR0=$(ifconfig enp0s31f6 | grep -E 'inet ' | awk '{print $2}')
# disk temperature
DISKS=($(lsblk -dl | tail -n +2 | grep -P -v "SWAP|loop" | cut -d' ' -f1))
DISK_TEMPS=''
for D in "${DISKS[@]}"; do
DEV="/dev/${D}"
temp=$(smartctl -A $DEV | grep 'Temperature' | head -n 1 | grep -oE '\s[0-9]{2}(\s|$)' | xargs)
health=$(smartctl -H $DEV | grep 'test result' | cut -d':' -f2 | xargs)
DISK_TEMPS+="$D,$temp,$health\n"
done
# zfs pools
BIFS="$IFS"
IFS=$'\n'
POOL_DATA=($(zpool list | tail -n +2))
POOLS=''
for P in "${POOL_DATA[@]}"; do
p_name=$(echo "$P" | awk '{print $1}')
p_size=$(echo "$P" | awk '{print $2}')
p_free=$(echo "$P" | awk '{print $4}')
p_health=$(echo "$P" | awk '{print $10}')
POOLS+="$p_name,$p_free/ $p_size,$p_health\n"
done
IFS="$BIFS"
#Return message
[ -z "$TEMPERATURE" ] && TEMPERATURE="not available"
[ -x "$(command -v sensors)" ] || TEMPERATURE="lm_sensors not found"
echo -ne "Generated at $(date)
System information
------------------
Hostname: $HOSTNAME
Release: $(</etc/redhat-release)
Users: Currently $(users | wc -w) user(s) logged on
IPv4 address for enp0: $IP_BR0
System load: $LOAD (1, 5, 15 min)
Memory usage: $MEMORY1 / $MEMORY2
Swap usage: $(free -m | tail -n 1 | awk '{print $3}') MB
Processes: $PSA
Uptime: $upDays days $upHours hours $upMins minutes $upSecs seconds
CPU Temperature: $TEMPERATURE
Disks
------------
"
printf "$DISK_TEMPS" | column --table --table-columns='Device,Temp (°C),Health' --separator=',' | awk '{print " " $0}'
echo -ne "
ZFS Pools
---------
"
printf "$POOLS" | column --table --table-columns='Pool,Usage,State' --separator=',' | awk '{print " " $0}'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment