64 lines
2.0 KiB
Bash
64 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
# This file was copied from a Scaleway server and tweaked so that it does
|
|
# not depends on Scaleway-specific commands and file. It should run fine
|
|
# on non-Scaleway hosts.
|
|
|
|
export PATH="${PATH:+$PATH:}/bin:/usr/bin:/usr/local/bin"
|
|
|
|
[ -r /etc/lsb-release ] && . /etc/lsb-release
|
|
[ -r /etc/scw-release ] && . /etc/scw-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
|
|
|
|
date=`date`
|
|
load=`cat /proc/loadavg | awk '{print $1}'`
|
|
root_usage=`df -h / | awk '/\// {print $(NF-1)}'`
|
|
memory_usage=`free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { printf("%3.1f%%", used/total*100)}'`
|
|
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", "exit !$2;$3/$2*100") }'`
|
|
users=`users | wc -w`
|
|
time=`uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }'`
|
|
processes=`ps aux | wc -l`
|
|
|
|
# Intermediate IP output for parsing public IPs (v4/v6)
|
|
ip=$(ip addr show $(ip route | grep default | cut -d' ' -f5))
|
|
|
|
# Global IPv4
|
|
ip4=$(echo "$ip" \
|
|
| grep "inet " \
|
|
| sed -e 's/^[ \t]*//' \
|
|
| cut -d' ' -f2 \
|
|
| cut -d/ -f1)
|
|
|
|
# Global IPv6
|
|
ip6=$(echo "$ip" \
|
|
| grep "inet6 " \
|
|
| grep "global" \
|
|
| sed -e 's/^[ \t]*//' \
|
|
| cut -d' ' -f2 \
|
|
| cut -d/ -f1)
|
|
|
|
KERNEL_VERSION=$(uname -r)
|
|
|
|
if [ -z "$IMAGE_DESCRIPTION" ]; then
|
|
source /etc/os-release
|
|
IMAGE_DESCRIPTION="$PRETTY_NAME"
|
|
fi
|
|
|
|
printf "\n"
|
|
[ -f /etc/motd.head ] && cat /etc/motd.head || true
|
|
printf "\n"
|
|
printf "Welcome on %s (%s %s %s)\n" "${IMAGE_DESCRIPTION}" "$(uname -o)" "${KERNEL_VERSION}" "$(uname -m)"
|
|
printf "System information as of: %s\n" "$date"
|
|
printf "\n"
|
|
printf "IPv4 Address:\t%s\n" $ip4
|
|
printf "IPv6 Address:\t%s\n" $ip6
|
|
printf "\n"
|
|
printf "System load:\t%s\t\tMemory usage:\t%s\n" $load $memory_usage
|
|
printf "Usage on /:\t%s\t\tSwap usage:\t%s\n" $root_usage $swap_usage
|
|
printf "Local Users:\t%s\t\tProcesses:\t%s\n" $users $processes
|
|
printf "System uptime:\t%s %s\n" $time
|
|
[ -f /etc/motd.tail ] && cat /etc/motd.tail || true
|