Skip to content

Instantly share code, notes, and snippets.

@bearlikelion
Created January 7, 2020 19:31
Show Gist options
  • Save bearlikelion/4feaa1ffbb64e6c22b99c0c7161c197d to your computer and use it in GitHub Desktop.
Save bearlikelion/4feaa1ffbb64e6c22b99c0c7161c197d to your computer and use it in GitHub Desktop.
Alpine Linux Dynamic MOTD
#!/bin/sh
#/etc/periodic/15min/motd
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
@bearlikelion
Copy link
Author

bearlikelion commented Jan 7, 2020

%--------------------------------------------------------------%
    Hostname: alpine.arneman.home
    Uptime: 27 days, 14 hours, 9 minutes
    Distro: #1-Alpine SMP Tue Jun 18 13:00:27 UTC 2019 with 4.19.52-0-virt

    CPU: 0.12, 0.11, 0.09
    Disk: 16.1G / 29.0G (58% used)
    Memory: 7903M / 7967M
    Swap: 864M / 1106M

    IP Address: 10.0.0.40
%--------------------------------------------------------------%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment