Skip to content

Instantly share code, notes, and snippets.

@mitcdh
Created March 6, 2018 00:43
Show Gist options
  • Save mitcdh/52c8a5d1ed00fd6fab948ddca8eb3698 to your computer and use it in GitHub Desktop.
Save mitcdh/52c8a5d1ed00fd6fab948ddca8eb3698 to your computer and use it in GitHub Desktop.
Script for update-motd that includes a system information snapshot
#!/bin/sh
date=$(date)
load=$(cat /proc/loadavg | awk '{print $1}')
root_usage=$(df -h / | awk '/\// {print $(NF-1)}')
memory_usage=$(free -m | awk '/Mem/{printf("%3.1f%%"), $3/$2*100}')
swap_usage=$(free -m | awk '/Swap/{printf("%3.1f%%"), $3/$2*100}')
users=$(users | wc -w)
time=$(uptime | awk -F'( |,|:)+' '{print $6,$7",",$8,"hours,",$9,"minutes"}')
processes=$(ps aux | wc -l)
ip4=$(ifconfig $(route | grep default | awk '{ print $8 }') | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}')
ip6=$(ifconfig $(route | grep default | awk '{ print $8 }') | grep "inet6 addr" | cut -d ' ' -f 13 | grep -vF fe80)
printf "\n"
printf "System information as of: %s\n" "$date"
printf "\n"
printf "System load:\t%s\t\tIPv4 Address:\t%s %s\n" "$load" "$ip4"
printf "Memory usage:\t%s\t\tIPv6 Address:\t%s\n" "$memory_usage" "$ip6"
printf "Usage on /:\t%s\t\tSwap usage:\t%s\n" "$root_usage" "$swap_usage"
printf "Local Users:\t%s\t\tProcesses:\t%s\n" "$users" "$processes"
#printf "Uptime:\t\t%s\n" "$time"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment