From 2ca44e3a5ce8feffcde38c0945e1c053fcc78511 Mon Sep 17 00:00:00 2001 From: Rabjerg Date: Wed, 4 Jul 2018 10:14:40 +0200 Subject: [PATCH] this is a bad commit description --- README.md | 8 +++++ update_motd.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 README.md create mode 100755 update_motd.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..369cf60 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Usage: +source the update_motd.sh in your .bashrc + +# Customization: +INTIP = Internal IP, greps the output of "ip addr show" and finds a wifi or ethernet interface with an IP + +Server uptime is a dirty "get uptime days" and breaks when uptime is below 24h + diff --git a/update_motd.sh b/update_motd.sh new file mode 100755 index 0000000..1365c49 --- /dev/null +++ b/update_motd.sh @@ -0,0 +1,91 @@ +#!/bin/bash +# Script to create motd with relevant information. +# Based upon script by Luis Felipe Sánchez +# https://github.com/lfelipe1501/Arch-MOTD +# Modyfied by A. Rabjerg + + +#Define output file + +# Collect information +#USERNAME=`$USER` +HOSTNAME=`uname -n` +KERNEL=`uname -r` +CPU=`awk -F '[ :][ :]+' '/^model name/ { print $2; exit; }' /proc/cpuinfo` +ARCH=`uname -m` +DISCTOT=`df -h | grep VG-home | awk '{print $2"B" }'` +DISCFREE=`df -h | grep VG-home | awk '{print $4"B" }'` +MEMORY1=`free -t -h -m | grep "Mem" | awk '{print $7"B";}'` +MEMORY2=`free -t -h -m | grep "Mem" | awk '{print $2"B";}'` + +# Get External IP, not a beautiful solution +# modify the grep in INTIP [wlp|enp] to fit the name of your interfaces +EXTIP=`curl -s ipecho.net/plain` +INTIP=`ip addr show | grep -E -m 1 "inet.[0-2][0-9][0-9]\..{1,}[wlp|enp][0-9]{1,2}s[0-9]{1,2}$" | awk '{print $2}'` +LOCATION=`curl -s "https://tools.keycdn.com/geo.json?host=$EXTIP" | awk -F ":" 'BEGIN { RS=","} {print $0'} | grep -E "city" | awk -F ":" '{print$2}'` + +#Time of day +HOUR=$(date +"%H") +if [ $HOUR -lt 12 -a $HOUR -ge 0 ] +then TIME="Morning" +elif [ $HOUR -lt 17 -a $HOUR -ge 12 ] +then TIME="Afternoon" +else TIME="Evening" +fi + +#System uptime +uptime=`cat /proc/uptime | cut -f1 -d.` +upDays=$((uptime/60/60/24)) +upHours=$((uptime/60/60%24)) +upMins=$((uptime/60%60)) +upSecs=$((uptime%60)) + +#server uptime +# serverUp=$(ssh -o connecttimeout=3 -p 27272 b1@location uptime | awk '{print $5}') + +#System load +LOAD1=`cat /proc/loadavg | awk {'print $1'}` +LOAD5=`cat /proc/loadavg | awk {'print $2'}` +LOAD15=`cat /proc/loadavg | awk {'print $3'}` + +#Color variable #W="\033[00;37m" +W="\033[0m" #White +B="\033[01;36m" #Blue +R="\033[01;31m" #Red (Unused) +G="\033[01;32m" #Green (Unused) +N="\033[01;34m" #Nice Blue + +#Background Colors +Wb="\033[0;49m" #Background Transparent +Yb="\033[01;43m" #Background Yellow +Blb="\033[01;100m" #Background Grey +Bb="\033[01;44m" #Background Blue +Yyb="\033[01;107m" #Background White +#N="\033[01;34m" + +echo -e "$N---------------------------------------------------------------" +echo -e " " +echo -e " $B$Bb $Wb $Blb $Wb" +echo -e " $B$Bb $Wb $Bb $Wb $Blb $Wb$N Linux/Open Source" +echo -e " $B$Bb $Wb $Bb $Wb $Yb $Blb $W$N Consulting, Training" +echo -e " $B$Bb $Wb $Bb $Wb $Blb $Wb$N Development & Support" +echo -e " $B$Bb $Wb $Yyb $Blb $Wb$N WWW.B1-SYSTEMS.DE" +echo -e " $B$Bb $Wb $Bb $Wb $Yyb $Blb $Wb" +echo -e " $B$Bb $Wb $Bb $Wb $Yyb $Blb $Wb$N KERNEL :$W $KERNEL $ARCH" +echo -e " $B$Bb $Wb $Bb $Wb $Yyb $Blb $Wb$N TOT. MEMORY :$W $MEMORY2" +echo -e " $B$Bb $Wb $Bb $Wb $Yyb $Blb $Wb$N FREE MEMORY :$W $MEMORY1" +echo -e " $B$Bb $Wb $Yyb $Wb$N $N EXTERNAL IP :$W $EXTIP $LOCATION" +echo -e " $N S Y S T E M S $N INTERNAL IP :$W $INTIP" +echo -e " $N" +echo -e "$N---------------------------------------------------------------" +echo -e "$N HD FREE / TOTAL :$W $DISCFREE / $W$DISCTOT " +echo -e "$N LOAD AVG :$W $LOAD1, $LOAD5, $LOAD15 " +echo -e "$N UPTIME :$W $upDays/d $upHours/h $upMins/m $upSecs/s " +echo -e "$N---------------------------------------------------------------" +echo -e " $W Please do not share your login and use$G sudo$W for$R root$W access " +echo -e "$N---------------------------------------------------------------" +echo -e "$N" +#echo -e "$N VPS # Core, #GB uptime = $serverUp days " +echo -e "$N " +echo -e "$N---------------------------------------------------------------" +echo -e "$N "