Created
January 7, 2014 02:59
-
-
Save chuckwagoncomputing/8294021 to your computer and use it in GitHub Desktop.
Dynamic Motd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clear | |
one() | |
{ | |
FILETEXT=`cat $FILE | tail -c +5` | |
echo $FILETEXT | |
rm -f $FILE | |
} | |
two() | |
{ | |
FILETEXT=`cat $FILE | tail -c +5` | |
echo $FILETEXT | |
rm -f $FILE | |
echo "one_$FILETEXT" >> $FILE | |
} | |
three() | |
{ | |
FILETEXT=`cat $FILE | tail -c +7` | |
echo $FILETEXT | |
rm -f $FILE | |
echo "two_$FILETEXT" >> $FILE | |
} | |
normal() | |
{ | |
tput sgr0 | |
} | |
green() | |
{ | |
tput sgr0 | |
tput setaf 2 | |
} | |
cyan() | |
{ | |
tput sgr0 | |
tput setaf 6 | |
} | |
red() | |
{ | |
tput setaf 1 | |
} | |
IAM=`logname` | |
FILE="/usr/notes/$IAM" | |
ME=`who | grep ^"$IAM"` | |
NAME=`getent passwd $IAM | cut -d ':' -f 5 | cut -d ',' -f 1 | cut -d ' ' -f 1` | |
MYTERM=`tty | cut -d "/" -f 3-` | |
WIDTH=`stty size | cut -d " " -f 2` | |
others() | |
{ | |
who | grep -v ^"$IAM" | |
} | |
cyan | |
if [ $WIDTH -gt 65 ]; then | |
echo -e " _____ _ _ __ __ | |
/ ____| | | | \ \ / / | |
| | | |__ _ _ ___| | _\ \ /\ / /_ _ __ _ ___ _ __ | |
| | | '_ \| | | |/ __| |/ /\ \/ \/ / _\` |/ _\` |/ _ \| '_ \ | |
| |____| | | | |_| | (__| < \ /\ / (_| | (_| | (_) | | | | | |
\_____|_| |_|\__,_|\___|_|\_\ \/ \/ \__,_|\__, |\___/|_| |_| | |
__/ | | |
|___/ | |
_____ _ _ | |
/ ____| | | (_) | |
| | ___ _ __ ___ _ __ _ _| |_ _ _ __ __ _ | |
| | / _ \| '_ \` _ \| '_ \| | | | __| | '_ \ / _\` | | |
| |___| (_) | | | | | | |_) | |_| | |_| | | | | (_| | | |
\_____\___/|_| |_| |_| .__/ \__,_|\__|_|_| |_|\__, | | |
| | __/ | | |
|_| |___/\n" | |
else | |
echo -e "ChuckWagon\nComputing\n" | |
fi | |
normal | |
red | |
for i in $(seq `echo "$WIDTH - 1" | bc`); do | |
echo -n "#" | |
done | |
echo -e "#\n" | |
normal | |
TIME=`uptime | sed 's/^.*up//' | awk -F, '{ if ( $3 ~ /user/ ) { print $1 $2 } else { print $1 }}' | sed -e 's/:/\ hours\ /' -e 's/ min//' -e 's/$/\ minutes/' | sed 's/^ *//'` | |
echo -n "This server has been running for " | |
green | |
echo -e "$TIME\n" | |
normal | |
if [ `echo -n "$ME" | wc -l` -ge 1 ]; then | |
green | |
echo -n "You" | |
normal | |
echo -n " are logged in on " | |
if [ `echo -n "$ME" | wc -l` -eq 1 ]; then | |
green | |
echo -n "one" | |
normal | |
echo " other terminal:" | |
elif [ `echo -n "$ME" | wc -l` -ge 2 ]; then | |
green | |
echo -n "$ME" | wc -l | tr -d [:blank:] | tr -d "\n" | |
normal | |
echo " other terminals:" | |
else | |
echo "Fatal error 1" | |
normal | |
exit 1 | |
fi | |
normal | |
green | |
echo "$ME" | grep -v $MYTERM | tr -s '[:blank:]' '?' | cut -d "?" -f 2 | tr '\n' ' ' | |
echo | |
normal | |
else | |
echo "This is your first login." | |
fi | |
echo -n "Your current terminal is" | |
green | |
echo " $MYTERM." | |
normal | |
if [ `others | wc -l` -ge 1 ]; then | |
listothers() | |
{ | |
others | cut -d " " -f 1 | awk '{for (i=1;i<=NF;i++) a[tolower($i)]++}END{for (i in a) print i" "a[i]}' | sort -nrk2 | |
} | |
for i in $(seq `listothers | wc -l`); do | |
echo | |
green | |
WHOZIT=`listothers | head -n $i | tail -n 1 | cut -d " " -f 1 | tr -d '\n'` | |
echo -n $WHOZIT | |
normal | |
NUM=`listothers | head -n $i | tail -n 1 | cut -d " " -f 2 | tr -d '\n'` | |
echo -n " is logged in on " | |
if [ $NUM -eq 1 ]; then | |
green | |
echo -n "one" | |
normal | |
echo " terminal:" | |
green | |
others | grep $WHOZIT | tr -s '[:blank:]' '?' | cut -d "?" -f 2 | tr '\n' ' ' | |
normal | |
elif [ $NUM -ge 2 ]; then | |
green | |
echo -n "$NUM" | |
normal | |
echo " terminals:" | |
green | |
others | grep $WHOZIT | tr -s '[:blank:]' '?' | cut -d "?" -f 2 | tr '\n' ' ' | |
normal | |
else | |
echo "Fatal error 2" | |
fi | |
echo | |
done | |
else | |
echo "No others are logged in." | |
fi | |
echo | |
if [ -f $FILE ] && [ "$IAM" != "root" ]; then | |
TIMES=`cat $FILE | cut -d _ -f 1` | |
if type -t $TIMES >> /dev/null; then | |
echo "Hello $NAME, a note has been left for you:" | |
$TIMES | |
echo | |
else | |
echo "Hello $NAME, a note has been left for you:" | |
cat $FILE | |
echo | |
fi | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment