Motd
MOTD - Message of a day - is a message (usually a quotation or a saying) that is displayed to you just after you successfully login to the system.
Setup
- In /etc/login.defs uncomment line saying MOTD_FILE (looks something like this : MOTD_FILE /etc/motd )
- Create a motd file specified above:
echo " Gentoo is great and so am I" > /etc/motd
Testing
Open a new console <ctrl>+<alt>+F1 and try to login, your MOTD should show up :)
Rotating MOTDs
Displaying the same message all the time would be quite boring, that's why one wants to rotate MOTDs automatically.
Here is a simple script that take list of one-per-line (enter separated :) ) MOTDs located in /etc/motds and rotates them "randomly" every day. In an editor, write this script:
#!/bin/bash
# motd_rotate.sh
# this script takes a random line from /etc/motds and inserts it to /etc/motd
# WATCHOUT: This script will override everything in your motd-file (/etc/motd)
# bugs/ideas, please contact me at markotahal@netscape.net
skip_lines=10 # heading in motds file; number of lines to be skipped
rand= # a random number
motds="/etc/motds" # path to motds list file
motd="/etc/motd" # motd system file
msg= # text printed in MOTD
if [ ! -f $motds ]; then echo "Error: Motds list file not found : $motds" 1>&2;
else # we're Ok, let's get working
# get a pseudo-random number
rand=$$
skip_lines=$(($skip_lines + 1 )) # increase $skip_lines +1
max_lines=`cat $motds | tail -n+${skip_lines} | wc -l 2>/dev/null` # how many motds do we have
# echo " we have $max_lines motds to choose from"
rand=$((${rand}%${max_lines}))
rand=$((rand + 1 )) # now, $rand is in range 1..$max_lines - so we can match a line in $motds
m=`cat $motds | tail -n+${skip_lines} | sed -e " ${rand}! d " 2>/dev/null ` # get the motd
msg="\n MOTDs brought to you by $HOSTNAME ($OSTYPE) \n \n \t $m \n"
echo -e $msg > $motd # print line number $rand to $motd
fi
Save this file somewhere safe,eg. /usr/local/bin
Make it writeable just by root:
# chmod go-w && chmod ugo+x
and if you want your MOTD to change daily, this can be achieved by using cron:
ln -s /usr/local/bin/motd_rotate.sh /etc/cron.daily/motd_rotate.sh
Now just pollute your /etc/motds file and you are ready to GO! :) PS: You can use \n \t and that sort of backslash-characters to format your motd ; eg line up \n \t line down
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.
