_______________________________________________________________ How to Change the Message Of the Day (MOTD) on Raspberry Pi _______________________________________________________________ # by WA8KIM / kim@kim125.com / EchoLink: WA8KIM-R / WiRES-X: Rm#21149 / Last updated 08/24/2015. # http://www.wa8kim.com/rpi.html # Best viewed in Notepad with Word Wrap OFF/UNCHECKED and in full screen Download the latest version of this file at: http://www.wa8kim.com/files/(RPi)%20MOTD%20-%20How%20To%20Change.txt # The /etc/motd file is displayed whenever someone connects. sudo nano /etc/motd - Remove contents (Erase the entire document) # This file erases any temporary motd messages upon reboot and sets it back to default. We want to disable this feature. sudo nano /etc/init.d/motd - Comment out: uname -snrvm > /var/run/motd.dynamic (Meaning, place a # in front of uname -s....) sudo nano /etc/ssh/sshd_config - Change from "PrintLastLog yes" to "PrintLastLog no" (toward the end of the file) # Next, we will create a new script that will display whenever someone logs in. # After typing the following command, the screen will be blank. Copy-and-paste all the content between the long lines of dashes. # The following example is for my EchoLink / VPN Multi-Server systems sudo nano /etc/motd.tcl ----------------------------------------------------------------------------------------------------------------------------------------------------- let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" let secs=$((${upSeconds}%60)) let mins=$((${upSeconds}/60%60)) let hours=$((${upSeconds}/3600%24)) let days=$((${upSeconds}/86400)) UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"` # get the load averages read one five fifteen rest < /proc/loadavg echo "$(tput setaf 2) ----------------------------------------------------------------------- .~~. .~~. `date +"%A, %e %B %Y, %r"` '. \ ' ' / .' `uname -srmo`$(tput setaf 1) .~ .~~~..~. : .~.'~'.~. : Uptime...........: ${UPTIME} ~ ( ) ( ) ~ Memory...........: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total) ( : '~'.~.'~' : ) Running Processes: `ps ax | wc -l | tr -d " "` ~ .~ ( ) ~. ~ LAN IP Address...: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` ( : '~' : ) Wifi IP Address..: `/sbin/ifconfig wlan0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` '~ .~~~. ~' WAN IP Address...: `wget -q -O - http://icanhazip.com/ | tail` '~' Weather for 48822: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=0&locCode=48822" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'` $(tput setaf 2)----------------------------------------------------------------------- $(tput setaf 3) WELCOME TO WA8KIM's `hostname` Multi-Server on Raspberry Pi... $(tput setaf 2)----------------------------------------------------------------------- $(tput setaf 1)To view EchoLink Server log, type '$(tput setaf 7)el$(tput setaf 1)' To view OpenVPN Server log, type '$(tput setaf 7)vpn$(tput setaf 1)' $(tput setaf 2)-----------------------------------------------------------------------$(tput sgr0)" ----------------------------------------------------------------------------------------------------------------------------------------------------- # Make the newly created file executable sudo chmod +x /etc/motd.tcl # Tell the RPi to run your new motd.tcl script whenever someone logs in sudo nano /etc/profile # Add '/etc/motd.tcl' to the end sudo nano /var/run/motd.dynamic # Erase all data here You're Done ! ! ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ MORE EXAMPLES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Below are other examples of MOTD screens: ___________________________________________________ EXAMPLE #1: Fancy File Downloaded From Internet ___________________________________________________ ---------------------------------------------------------------------------------------------------------------------------------------------------- #!/usr/bin/env tclsh # MOTD script original? / mod mewbies.com # * Variables set var(user) $env(USER) set var(path) $env(PWD) set var(home) $env(HOME) # * Check if we're somewhere in /home #if {![string match -nocase "/home*" $var(path)]} { if {![string match -nocase "/home*" $var(path)] && ![string match -nocase "/usr/home*" $var(path)] } { return 0 } # * Calculate last login set lastlog [exec -- lastlog -u $var(user)] set ll(1) [lindex $lastlog 7] set ll(2) [lindex $lastlog 8] set ll(3) [lindex $lastlog 9] set ll(4) [lindex $lastlog 10] set ll(5) [lindex $lastlog 6] # * Calculate current system uptime set uptime [exec -- /usr/bin/cut -d. -f1 /proc/uptime] set up(days) [expr {$uptime/60/60/24}] set up(hours) [expr {$uptime/60/60%24}] set up(mins) [expr {$uptime/60%60}] set up(secs) [expr {$uptime%60}] # * Calculate usage of home directory set usage [lindex [exec -- /usr/bin/du -ms $var(home)] 0] # * Calculate SSH logins: set logins [lindex [exec -- who -q | cut -c "9-11"] 0] # * Calculate processes set psu [lindex [exec -- ps U $var(user) h | wc -l] 0] set psa [lindex [exec -- ps -A h | wc -l] 0] # * Calculate current system load set loadavg [exec -- /bin/cat /proc/loadavg] set sysload(1) [lindex $loadavg 0] set sysload(5) [lindex $loadavg 1] set sysload(15) [lindex $loadavg 2] # * Calculate Memory set memory [exec -- free -m] set mem(t) [lindex $memory 7] set mem(u) [lindex $memory 8] set mem(f) [lindex $memory 9] set mem(c) [lindex $memory 16] set mem(s) [lindex $memory 19] # * ascii berry set head { .~ .~~~..~. _ _ : .~.'~'.~. : ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_| ~ ( ) ( ) ~ | _| .'|_ -| . | . | -_| _| _| | | | . | | ( : '~'.~.'~' : ) |_| |__,|___| _|___|___|_| |_| |_ | | _|_| ~ .~ ( ) ~. ~ |_| |___| |_| ( : '~' : ) '~ .~~~. ~' '~'} # * ascii leaf set head2 { .~~. .~~. '. \ ' ' / .'} # * display kernel version set uname [exec -- /bin/uname -snrvm] set unameoutput0 [lindex $uname 0] set unameoutput [lindex $uname 1] set unameoutput2 [lindex $uname 2] set unameoutput3 [lindex $uname 3] set unameoutput4 [lindex $uname 4] # * display temperature set temp [exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"] set tempoutput [lindex $temp 0] # * display GPU version set gpu [exec -- /opt/vc/bin/vcgencmd version] set gpuoutput [lindex $gpu 0] set gpuoutput1 [lindex $gpu 1] set gpuoutput2 [lindex $gpu 2] set gpuoutput3 [lindex $gpu 8] set gpuoutput4 [lindex $gpu 9] # * Print Results puts "\033\[01;32m$head2\033\[0m" puts "\033\[02;31m$head\033\[0m" puts " System........: $unameoutput0 $unameoutput $unameoutput2 $unameoutput3 $unameoutput4" puts " GPU Version...: $gpuoutput $gpuoutput1 $gpuoutput2, $gpuoutput3 $gpuoutput4" puts " Last Login....: $ll(1) $ll(2) $ll(3) $ll(4) from $ll(5)" puts " Uptime........: $up(days)days $up(hours)hours $up(mins)minutes $up(secs)seconds" puts " Temperature...: $tempoutput°C" puts " Load..........: $sysload(1) (1minute) $sysload(5) (5minutes) $sysload(15) (15minutes)" puts " Memory MB.....: Total: $mem(t) Used: $mem(u) Free: $mem(f) Cached: $mem(c) Swap: $mem(s)" puts " Disk Usage....: You're using ${usage}MB in $var(home)" puts " SSH Logins....: Currently $logins user(s) logged in." puts " Processes.....: You're running ${psu} which makes a total of ${psa} running" if {[file exists /etc/changelog]&&[file readable /etc/changelog]} { puts " . .. More or less important system informations:\n" set fp [open /etc/changelog] while {-1!=[gets $fp line]} { puts " ..) $line" } close $fp puts "" } ----------------------------------------------------------------------------------------------------------------------------------------------------- ______________________________ EXAMPLE #2: Basic Template ______________________________ ----------------------------------------------------------------------------------------------------------------------------------------------------- let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" let secs=$((${upSeconds}%60)) let mins=$((${upSeconds}/60%60)) let hours=$((${upSeconds}/3600%24)) let days=$((${upSeconds}/86400)) UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"` # get the load averages read one five fifteen rest < /proc/loadavg echo "$(tput setaf 2) .~~. .~~. `date +"%A, %e %B %Y, %r"` '. \ ' ' / .' `uname -srmo`$(tput setaf 1) .~ .~~~..~. : .~.'~'.~. : Uptime.............: ${UPTIME} ~ ( ) ( ) ~ Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total) ( : '~'.~.'~' : ) Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min) ~ .~ ( ) ~. ~ Running Processes..: `ps ax | wc -l | tr -d " "` ( : '~' : ) IP Addresses.......: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` and `wget -q -O - http://icanhazip.com/ | tail` '~ .~~~. ~' Weather............: `curl -s ""http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=48822" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'` '~' $(tput sgr0)" ----------------------------------------------------------------------------------------------------------------------------------------------------- _______________________________________________ EXAMPLE #3: SVXLink Server for 3.2in Screen _______________________________________________ ----------------------------------------------------------------------------------------------------------------------------------------------------- let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" let secs=$((${upSeconds}%60)) let mins=$((${upSeconds}/60%60)) let hours=$((${upSeconds}/3600%24)) let days=$((${upSeconds}/86400)) UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"` # get the load averages read one five fifteen rest < /proc/loadavg echo "$(tput setaf 2) `date +"%A, %e %B %Y, %r"` `uname -srmo`$(tput setaf 1) Uptime...........: ${UPTIME} Memory...........: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total) Running Processes: `ps ax | wc -l | tr -d " "` LAN IP Address...: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` Wifi IP Address..: `/sbin/ifconfig wlan0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` WAN IP Address...: `wget -q -O - http://icanhazip.com/ | tail` Weather for 48822: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=0&locCode=48822" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'` $(tput setaf 2)----------------------------------------------------- Welcome to WA8KIM's SVXLink Server on Raspberry Pi... ----------------------------------------------------- $(tput setaf 1)To view SVXLink activity, type '$(tput setaf 3)el$(tput setaf 1)' - To exit, type '$(tput setaf 3)[CTRL-A] $(tput setaf 1)then $(tput setaf 3)d$(tput setaf 1)' to detach To view Wifi manager, type '$(tput setaf 3)wifi$(tput setaf 1)' -----------------------------------------------------$(tput sgr0)" ----------------------------------------------------------------------------------------------------------------------------------------------------- _____________________________________ EXAMPLE #4: Basic Welcome Screen _____________________________________ ----------------------------------------------------------------------------------------------------------------------------------------------------- let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" let secs=$((${upSeconds}%60)) let mins=$((${upSeconds}/60%60)) let hours=$((${upSeconds}/3600%24)) let days=$((${upSeconds}/86400)) UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"` # get the load averages read one five fifteen rest < /proc/loadavg echo "$(tput setaf 2) ----------------------------------------------------------------------- .~~. .~~. `date +"%A, %e %B %Y, %r"` '. \ ' ' / .' `uname -srmo`$(tput setaf 1) .~ .~~~..~. : .~.'~'.~. : Uptime...........: ${UPTIME} ~ ( ) ( ) ~ Memory...........: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total) ( : '~'.~.'~' : ) Running Processes: `ps ax | wc -l | tr -d " "` ~ .~ ( ) ~. ~ LAN IP Address...: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` ( : '~' : ) Wifi IP Address..: `/sbin/ifconfig wlan0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` '~ .~~~. ~' WAN IP Address...: `wget -q -O - http://icanhazip.com/ | tail` '~' Weather for 48822: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=0&locCode=48822" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'` $(tput setaf 2)----------------------------------------------------------------------- $(tput setaf 3) WELCOME TO WA8KIM's `hostname` Raspberry Pi... $(tput setaf 2)----------------------------------------------------------------------- $(tput setaf 1)Installed Programs: Tight VNC, GNU Screen, WICD Curses, ddclient, Links Visit my website at $(tput setaf 7)http://www.WA8KIM.com$(tput setaf 1) , Email: $(tput setaf 7)kim@kim125.com $(tput setaf 1)To view Wifi manager, type '$(tput setaf 3)wifi$(tput setaf 1)' $(tput setaf 1)To browse websites, type '$(tput setaf 3)links website.com$(tput setaf 1)' $(tput setaf 2)-----------------------------------------------------------------------$(tput sgr0)" ----------------------------------------------------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~ ALTERNATE METHOD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # By simply creating the following file in your home folder (ex: /home/pi), it will be displayed at each login after the previous content. sudo nano /home/pi/.bash_profile ----------------------------------------------------------------------------------------------------------------------------------------------------- (Place your MOTD content here) ----------------------------------------------------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ LINKS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ http://www.mewbies.com/how_to_customize_your_console_login_message_tutorial.htm http://www.raspberrypi.org/forums/viewtopic.php?t=23440 https://wiki.debian.org/motd#How_to_script_updates_to_your_.2BAC8-etc.2BAC8-motd -------------------- REVISION HISTORY -------------------- 2015-08-24 Updated Download Link 2015-03-19 File Created