-
-
Save bearlikelion/ab56fc137581b9e8aed1974badb7656b to your computer and use it in GitHub Desktop.
Dynamic motd generator for Alpine Linux (/etc/periodic/15min/motd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: `hostname`.`dnsdomainname` | |
Uptime: $UPTIME_DAYS days, $UPTIME_HOURS hours, $UPTIME_MINUTES minutes | |
Distro: `uname -v` with `uname -r` | |
CPU: `cat /proc/loadavg | awk '{print $1 ", " $2 ", " $3}'` | |
Disk: `df -h / | tail -n 1 | awk {'print $3'}` / `df -h / | tail -n 1 | awk {'print $2'}` (`df -h / | tail -n 1 | awk {'print $5'}` used) | |
Memory: `free -m | head -n 2 | tail -n 1 | awk {'print $3'}`M / `free -m | head -n 2 | tail -n 1 | awk {'print $2'}`M | |
Swap: `free -m | tail -n 1 | awk {'print $3'}`M / `free -m | tail -n 1 | awk {'print $4'}`M | |
IP Address: `ifconfig eth0 | 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
Example
Usage
Create /etc/periodic/15min/motd
Paste gist
chmod +x motd
/etc/periodic/15min/motd
cat /etc/motd