Skip to content

Instantly share code, notes, and snippets.

@IllyaTheHath
Last active February 22, 2023 09:40
Show Gist options
  • Save IllyaTheHath/fc31b42a00e7660adc1c78202bd7b48a to your computer and use it in GitHub Desktop.
Save IllyaTheHath/fc31b42a00e7660adc1c78202bd7b48a to your computer and use it in GitHub Desktop.
Debian motd
#!/bin/sh
#
# 00-header - create the header of the MOTD
# Copyright (C) 2009-2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
[ -r /etc/lsb-release ] && . /etc/lsb-release
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
# Fall back to using the very slow lsb_release utility
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)"
echo
#!/bin/bash
# date
date=`date`
# System load
load=`cat /proc/loadavg | awk '{print $1}'`
# Root usage
root_usage_percent=`df -h / | awk '/\// {print $(NF-1)}'`
root_usage_size=` df -h / | awk '/\// {print $(NF-3)}'`
root_size=`df -h / | awk '/\// {print $(NF-4)}'`
root_usage=`printf "%s, %s of %s" $root_usage_percent $root_usage_size $root_size`
# Mem usage
memory_usage=`free -m | awk '/Mem:/ { total=$2; used=$3 } END { printf("%3.1f%%", used/total*100)}'`
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'`
# Processes
processes=`ps aux | wc -l`
# Logged user
users=`users | wc -w`
# Uptime
time=`uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }'`
echo " System information as of $date"
echo
printf " System load:\t\t\t%s\n" $load
printf " Usage of /:\t\t\t%s\n" "$root_usage"
printf " Memory usage:\t\t\t%s\n" $memory_usage
printf " Swap usage:\t\t\t%s\n" $swap_usage
printf " Processes:\t\t\t%s\n" $processes
printf " Users logged in:\t\t%s\n" $users
printf " System uptime:\t\t%s\n" "$time"
# IP Address
nets=`ip a | grep -E 'eno[0-9]+:|ens[0-9]+:|enp[0-9]+s[0-9]+:|eth[0-9]+:|eth[0-9]+@if[0-9]+:|wlp[0-9]+s[0-9]+:' | awk '{ print $2 }' | sed 's/://g'`
for net in $nets
do
ipv4=`ip a s $net | grep inet | awk '{ print $2 }' | head -1`
printf " IPv4 address for %s:\t%s" $net $ipv4
printf "\n"
ipv6=`ip a s $net | grep inet6 | awk '{ print $2 }' | head -1`
printf " IPv6 address for %s:\t%s" $net $ipv6
done
echo
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment