scripts/aech/motd.sh

71 lines
2.3 KiB
Bash

##!/bin/bash
# MOTD script
# Variables
user=$USER
path=$PWD
home=$HOME
# Calculate last login
lastlog=$(lastlog -u $user | tail -n 1)
ll[0]=$(echo $lastlog | awk '{print $4}')
ll[1]=$(echo $lastlog | awk '{print $5}')
ll[2]=$(echo $lastlog | awk '{print $6}')
ll[3]=$(echo $lastlog | awk '{print $7}')
ll[4]=$(echo $lastlog | awk '{print $3}')
# Calculate current system uptime
uptime=$(uptime -p|cut -c 4-)
upsince=$(uptime -s)
# Calculate usage of disk
usage=$(df -h / | head -n 2 | tail -n 1 | awk '{print $3}')
usageTotal=$(df -h / | head -n 2 | tail -n 1 | awk '{print $2}')
# Calculate SSH logins
logins=$(w -s|head -n1|awk '{print $6}')
# Calculate processes
psa=$(($(ps -A h | wc -l)-2))
# Calculate current system load
loadavg=$(cat /proc/loadavg)
sysload[1]=$(echo $loadavg|awk '{print $1}')
sysload[5]=$(echo $loadavg|awk '{print $2}')
sysload[15]=$(echo $loadavg|awk '{print $3}')
# Calculate Memory
memory=$(free -mh|head -n2|tail -n1)
memT=$(echo $memory|awk '{print $2}')
memU=$(echo $memory|awk '{print $3}')
memF=$(echo $memory|awk '{print $4}')
memC=$(echo $memory|awk '{print $6}')
memory=$(free -mh|tail -n1)
memS=$(echo $memory|awk '{print $3}')
# ASCII head
head=$(cat <<EOF
, ,
'"\_ ,/",
\.'\_ ,/ ,/ /) /) , /)
\.'\_ ,/ ,/ _ __ // // __ _(/ _____
\.'\__/ ,/ (_/_/ (_(_/_/(_/(__(_/ (_(_(_(_)/ (_
\{00}/ .-/ .-/ /) /)
\ / (_/ (_/ (/ (/
+==""==+
<<< ${user}@$(hostname) >>>
EOF
)
# Print Output
echo -e "\033[01;32m$head\033[0m"
echo -e " \033[35mLast Login....:\033[0m \033[36m${ll[1]} ${ll[2]} ${ll[3]} from ${ll[4]}\033[0m \033[33m${ll[5]}\033[0m"
echo -e " \033[35mUptime........:\033[0m \033[36m$uptime (since $upsince)\033[0m"
echo -e " \033[35mLoad..........:\033[0m \033[36m${sysload[1]} (1minute) ${sysload[5]} (5minutes) ${sysload[15]} (15minutes)\033[0m"
echo -e " \033[35mMemory MB.....:\033[0m \033[36m$memT Used: $memU Free: $memF Free Cached: $memC Swap Used: $memS\033[0m"
echo -e " \033[35mDisk Usage....:\033[0m \033[36m$usage out of $usageTotal\033[0m"
echo -e " \033[35mSSH Logins....:\033[0m \033[36mThere are currently $logins active sessions\033[0m"
echo -e " \033[35mProcesses.....:\033[0m \033[36m$psa total running\033[0m\n"