Skip to content

Instantly share code, notes, and snippets.

@ergoz
Last active February 8, 2024 10:18
Show Gist options
  • Save ergoz/78c1e956290dac0de4082eab0655f828 to your computer and use it in GitHub Desktop.
Save ergoz/78c1e956290dac0de4082eab0655f828 to your computer and use it in GitHub Desktop.
Dynamic motd generator for Alpine Linux (/etc/periodic/15min/motd)
#!/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
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
% %
% WELCOME! %
% %
% This is a server. %
% %
% %
%+++++++++++++++++++++++++++++++ SERVER INFO ++++++++++++++++++++++++++++++++%
% %
Name: `hostname`
Uptime: $UPTIME_DAYS days, $UPTIME_HOURS hours, $UPTIME_MINUTES minutes
CPU: `cat /proc/cpuinfo | grep 'model name' | head -1 | cut -d':' -f2`
Memory: `free -m | head -n 2 | tail -n 1 | awk {'print $2'}`M
Swap: `free -m | tail -n 1 | awk {'print $2'}`M
Disk: `df -h / | awk '{ a = $2 } END { print a }'`
Distro: `uname -v` with `uname -r`
CPU Load: `cat /proc/loadavg | awk '{print $1 ", " $2 ", " $3}'`
Free Memory: `free -m | head -n 2 | tail -n 1 | awk {'print $4'}`M
Free Swap: `free -m | tail -n 1 | awk {'print $4'}`M
Free Disk: `df -h / | awk '{ a = $2 } END { print a }'`
eth0 Address: `ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
eth1 Address: `ifconfig eth1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
eth2 Address: `ifconfig eth2 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
% %
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment