Skip to content

Instantly share code, notes, and snippets.

@hongkongkiwi
Created May 8, 2019 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongkongkiwi/9beb848f660bfb29d4d8b2a5296ea9a4 to your computer and use it in GitHub Desktop.
Save hongkongkiwi/9beb848f660bfb29d4d8b2a5296ea9a4 to your computer and use it in GitHub Desktop.
Please this script into /etc/periodic/15m/motd to generate a message of the day every 15 mins
#!/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)
FIRST=yes
for iface in $(ls -A /sys/class/net | grep eth)
do
INTERFACE="`echo "$iface" | sed 's/.*/\u&/'` Address: `ifconfig $iface | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`"
if [ $FIRST == "no" ]; then
INTERFACES=`printf "$INTERFACE\n"`
FIRST=no
else
INTERFACES=`printf "$INTERFACES\n # $INTERFACE\n"`
fi
done
PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
if [ "$PUBLIC_IPv4" != "not found" ]; then
INTERFACES=`printf "$INTERFACES\n # Public Address: $PUBLIC_IPV4\n"`
fi
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'}`
# Swap: `free -m | tail -n 1 | awk {'print $2'}`
# 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'}`
# Free Swap: `free -m | tail -n 1 | awk {'print $4'}`
# Free Disk: `df -h / | awk '{ a = $2 } END { print a }'`
# $INTERFACES
# #
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment