Skip to content

Instantly share code, notes, and snippets.

@rupertbenbrook
Created August 8, 2021 16:40
Show Gist options
  • Save rupertbenbrook/4bf2c50a9ed56108daa41f3692be0ddf to your computer and use it in GitHub Desktop.
Save rupertbenbrook/4bf2c50a9ed56108daa41f3692be0ddf to your computer and use it in GitHub Desktop.
Motd generator - goes in /etc/periodic/15min/motd.sh
#!/bin/sh
UPTIME_DAYS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 / 86400)
UPTIME_HOURS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 / 3600)
UPTIME_MINUTES=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 % 3600 / 60)
cat > /etc/motd << EOF
____ _ _
| _ \ | | | |
| |_) | ___ _ __ | |__ _ __ ___ ___ | | __
| _ < / _ \ '_ \| '_ \| '__/ _ \ / _ \| |/ /
| |_) | __/ | | | |_) | | | (_) | (_) | <
|____/ \___|_| |_|_.__/|_| \___/ \___/|_|\_\\
`hostname -f` (`ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`)
`uname -v` with `uname -r`
Uptime: $UPTIME_DAYS days, $UPTIME_HOURS hours, $UPTIME_MINUTES minutes
Memory: `free -m | head -n 2 | tail -n 1 | awk {'print $2'}`M / `free -m | head -n 2 | tail -n 1 | awk {'print $4'}`M free
Swap: `free -m | tail -n 1 | awk {'print $2'}`M / `free -m | tail -n 1 | awk {'print $4'}`M free
Disk: `df -h / | awk '{ a = $2 } END { print a }'` / `df -h / | awk '{ a = $4 } END { print a }'` free
CPU Load: `cat /proc/loadavg | awk '{print $1 ", " $2 ", " $3}'`
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment