Skip to content

Instantly share code, notes, and snippets.

@bearlikelion
Forked from ergoz/motd_generator.sh
Last active February 8, 2024 10:19
Show Gist options
  • Save bearlikelion/ab56fc137581b9e8aed1974badb7656b to your computer and use it in GitHub Desktop.
Save bearlikelion/ab56fc137581b9e8aed1974badb7656b 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
%--------------------------------------------------------------%
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 Jun 28, 2019

Example

 %--------------------------------------------------------------%
      Hostname: alpine.arneman.home
      Uptime: 2 days, 23 hours, 46 minutes
      Distro: #1-Alpine SMP Thu May 9 10:57:44 UTC 2019 with 4.19.41-0-virt

      CPU: 0.13, 0.07, 0.02
      Disk: 3.4G / 13.3G (27% used)
      Memory: 1012M / 4040M
      Swap: 0M / 1970M

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

Usage

Create /etc/periodic/15min/motd
Paste gist
chmod +x motd
/etc/periodic/15min/motd
cat /etc/motd

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