Skip to content

Instantly share code, notes, and snippets.

@maximishchenko
Last active January 3, 2025 21:35
Show Gist options
  • Select an option

  • Save maximishchenko/664e8829190e69731d97ab189fc93f76 to your computer and use it in GitHub Desktop.

Select an option

Save maximishchenko/664e8829190e69731d97ab189fc93f76 to your computer and use it in GitHub Desktop.
Bash Motd Generator Script
#!/bin/bash
#FILE="/home/user/scripts/motd"
FILE="/etc/motd"
INSTDATE=$(date +%F)
HOSTNAME=$(hostname)
OSRELASE=$(cat /etc/*release | head -1)
#OSDETECT="i-have-to-define"
#IPADDRES=$(ifconfig eth0 | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | head -1)
ETHERADD=$(ifconfig |grep -e ^[a-z] |grep -v lo | awk '{ printf $1 FS}')
INTERFACE=$(hostname -I)
# if [ -w $FILE ]
# then
# if [[ -n `egrep -o '[0-9]+++-[0-9]++-[0-9]++' $FILE` ]]
# then
# IDATE=$(egrep -o '[0-9]+++-[0-9]++-[0-9]++' $FILE)
# echo "$FILE was in past $IDATE altered"
# echo "Will be saved as .rpmsave"
# FILE=$FILE.rpmsave
# fi
# else
# logger -p local0.warn -t ME "`id -un` is not allowed to edit $FILE"
# echo "File is not Writeable. You are Not allowed to chance Motd"
# echo "Will be saved as .rpmsave"
# FILE=$FILE.rpmsave
# fi
cat << End-of-Message > $FILE
`echo -en "\033[1;31m"`
* * * * * * * * * * * * *: W A R N I N G :* * * * * * * * * * * * * *
*THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS FOR AUTHORIZED USE ONLY*
* UNAUTHORIZED ACCESS IS STRICTLY PROHIBITED AND MAY BE PUNISHED *
* * * * * * * * * * * * *: W A R N I N G :* * * * * * * * * * * * * *
* $INSTDATE *
End-of-Message
printf " * %-16s%-42s*\n" "Hostname:" "$HOSTNAME" >>$FILE
printf " * %-16s%-42s*\n" "OS:" "$OSRELASE" >>$FILE
#printf " * %-16s%-42s*\n" "HW:" "$OSDETECT" >>$FILE
#printf " * %-16s%-42s*\n" "IP:" "$INTERFACE" >>$FILE
#printf " * %-16s%-42s*\n" "IP:" "$IPADDRES" >>$FILE
for i in $ETHERADD
do
IP=$(ifconfig $i | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | head -1)
printf " * %-16s%-42s*\n" "IP $i" "$INTERFACE" >>$FILE
done
cat << End-of-Message >> $FILE
* *
* Contact: Alliance Company Group *
* 347 km "Caucasus" Road *
* Russia *
* Administrator: it@alians-kmv.ru *
* *
* Status: Productive *
***********************************************************************
`echo -en "\033[0m"`
End-of-Message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment