bfesser
Posts: 7
Joined: Sun Jan 13, 2013 6:48 pm
Location: MN, US

Re: Custom MOTD - Message of the Day

Thu Jan 17, 2013 2:09 am

Igneosaur wrote:It's been a while since I played around with my pi and I had coloured promts set up, but after I created a .bash_profile and put this script in, I've lost my coloured prompt. I don't really get what's going on here, could anyone here fill me in?
I had the same thing happen. In my case, I just removed .bash_profile.
A few references for you to check out:
http://www.joshstaiger.org/archives/200 ... le_vs.html (see Recommendation)
http://www.picymru.com/325

I think you'll want to include the bash color code from .bashrc into your .bash_profile, as follows:

Code: Select all

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  # We have color support; assume it's compliant with Ecma-48
  # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  # a case would tend to support setf rather than setaf.)
  color_prompt=yes
    else
  color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w\$ '
fi
unset color_prompt force_color_prompt
I really hope this solves your problem. I know I was really bummed when I lost color. It just made things so much easier to read!

anslo
Posts: 2
Joined: Sat Jan 19, 2013 8:39 pm

Re: Custom MOTD - Message of the Day

Sat Jan 19, 2013 8:43 pm

Great post & comments!

However, when I followed the original instructions, I get an error that I cannot figure out.

Any ideas?
Linux raspberrypi 3.6.11+ #358 PREEMPT Tue Jan 15 00:45:33 GMT 2013 armv6l
Last login: Sat Jan 19 21:32:44 2013 from localhost
init
child process exited abnormally
while executing
"exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9""
invoked from within
"set temp [exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"]"
(file "/etc/motd.tcl" line 76)

User avatar
azeam
Posts: 194
Joined: Fri Oct 26, 2012 11:13 pm
Contact: Website

Re: Custom MOTD - Message of the Day

Sun Jan 20, 2013 1:16 pm

anslo wrote:Great post & comments!

However, when I followed the original instructions, I get an error that I cannot figure out.

Any ideas?
Linux raspberrypi 3.6.11+ #358 PREEMPT Tue Jan 15 00:45:33 GMT 2013 armv6l
Last login: Sat Jan 19 21:32:44 2013 from localhost
init
child process exited abnormally
while executing
"exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9""
invoked from within
"set temp [exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"]"
(file "/etc/motd.tcl" line 76)
Can you paste the output of

Code: Select all

/opt/vc/bin/vcgencmd measure_temp
and

Code: Select all

/opt/vc/bin/vcgencmd commands

mrburns42
Posts: 25
Joined: Thu Jan 24, 2013 7:00 pm

Re: Custom MOTD - Message of the Day

Thu Jan 24, 2013 7:16 pm

I tried several times to follow the directions, but I keep getting errors when I try to execute the script:
Below is an example of the error.

/etc/./motd.tcl: line 5: syntax error near unexpected token `('
/etc/./motd.tcl: line 5: ` set var(user) $env(USER)'

Looking at the code, I do not see anything wrong. Searching the Internet, this error is fairly common when building tcl, but I am not building it.

Since others are running OK, it must either be something very dumb that I am doing, or my PI has something installed that it causing this.

Has anyone else had this error? If so, what was the solution?

Thanks.

Steve

mrburns42
Posts: 25
Joined: Thu Jan 24, 2013 7:00 pm

Re: Custom MOTD - Message of the Day

Fri Jan 25, 2013 3:17 am

Ok, I figured out what was causing my syntax errors. I was copying the code into the clipboard and then pasting into nano running via ssh. Somehow, this was pasting in with extra spaces at the beginning of each line. Since the beginning of each line had the same amount of white space, I did not notice the offset.

I believe the shebang on the first line must be in column zero or it does not understand what kind of script it is.

anslo
Posts: 2
Joined: Sat Jan 19, 2013 8:39 pm

Re: Custom MOTD - Message of the Day

Mon Jan 28, 2013 10:08 pm

Thanks for offering to help. I made a mess and decided to start with a totally clean installation. Realise I need to brush up on basic Linux skills. For now, I'll stick to the original post which works well - and gives me local weather info.

Thanks again.

A.
azeam wrote:
anslo wrote:Great post & comments!

However, when I followed the original instructions, I get an error that I cannot figure out.

Any ideas?
Linux raspberrypi 3.6.11+ #358 PREEMPT Tue Jan 15 00:45:33 GMT 2013 armv6l
Last login: Sat Jan 19 21:32:44 2013 from localhost
init
child process exited abnormally
while executing
"exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9""
invoked from within
"set temp [exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"]"
(file "/etc/motd.tcl" line 76)
Can you paste the output of

Code: Select all

/opt/vc/bin/vcgencmd measure_temp
and

Code: Select all

/opt/vc/bin/vcgencmd commands

sigwo
Posts: 5
Joined: Mon Feb 18, 2013 6:26 pm
Location: Leavenworth, KS
Contact: Website

Re: Custom MOTD - Message of the Day

Mon Feb 18, 2013 6:30 pm

Thanks for the awesome login banner. I ran into losing my color scheme, and found an answer. At the end of your /.bash_profile, insert

Code: Select all

if [ -f ~/.bashrc ]
then
    source ~/.bashrc
fi
then exit/save/logout. Log back in to see your colors.

sigwo
Posts: 5
Joined: Mon Feb 18, 2013 6:26 pm
Location: Leavenworth, KS
Contact: Website

Re: Custom MOTD - Message of the Day

Thu Feb 21, 2013 12:15 am

I think you'll want to include the bash color code from .bashrc into your .bash_profile, as follows:
Would it not work if we put the banner information from the original post at the bottom of the .bash_profile page?

payne747
Posts: 9
Joined: Fri Jun 01, 2012 1:38 pm
Location: Hampshire, UK
Contact: Website

Re: Custom MOTD - Message of the Day

Sun Mar 17, 2013 2:32 pm

Great script, however moving it to the motd wasn't really useful as this is dynamically created by /etc/init.d/motd on boot, so the uptime was always 0 ;)
John Payne
http://www.the-serpent.co.uk

borsitsb
Posts: 5
Joined: Fri Mar 15, 2013 11:52 am

Re: Custom MOTD - Message of the Day

Sun Mar 17, 2013 2:44 pm

I would like to set this motd to my Raspberry Pi, but I can't :( . Could anyone write me a little tutorial? I'm a beginner Linux user. Thank you! :)

Metapony
Posts: 1
Joined: Tue Mar 19, 2013 4:46 am

Re: Custom MOTD - Message of the Day

Thu Apr 04, 2013 11:47 am

I had some errors with the code (mostly the free disk space) in this thread, and can't recall where exactly where I got this longer version, but I'll include it here. Change the zip code!

Code: Select all

source ~/.profile
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 


# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  # We have color support; assume it's compliant with Ecma-48
  # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  # a case would tend to support setf rather than setaf.)
  color_prompt=yes
    else
  color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to [email protected]:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\[email protected]\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

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)
( : '~'.~.'~' : ) CPU Temperature....: `exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"`
 ~ .~ (   ) ~. ~  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=0&locCode=NAM|US|VA|20175" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'`
                  Free Disk Space SD.: `df -Pk | grep -E '/root' | awk '{ print $4 }' | awk -F '.' '{ print $1 }'`k on /root

$(tput sgr0)"

Eliot
Posts: 1
Joined: Sun May 05, 2013 9:10 am

Re: Custom MOTD - Message of the Day

Sun May 05, 2013 9:15 am

There's a much simpler solution in Raspbian Wheezy. Just edit /etc/motd to contain the desired text. There will still be an autogenerated line at the top of the file but it contains useful info so I left it there. If you really want to get rid of it you can follow the instructions above to disable the job in /etc/init.d and delete the motd.dynamic file.

felmoltor
Posts: 1
Joined: Mon May 20, 2013 8:03 am

Re: Custom MOTD - Message of the Day

Mon May 20, 2013 8:10 am

Hi @azeam.

Cool summary to create the dynamic motd.
One little fix on line 34:

The line shoud be like this:

Code: Select all

set logins    [lindex [exec -- who -q | tail -n 1 |  cut -d= -f2] 0]
instead of:

Code: Select all

set logins    [lindex [exec -- who -q | cut -c "9-11"] 0]
At least, for me, wast not working well with a raspbian weezy 7.0 and was showing a message like that
"SSH Logins....: Currently r user(s) logged in."

Thanks again! :D

dehein
Posts: 27
Joined: Fri Mar 01, 2013 9:46 pm

Re: Custom MOTD - Message of the Day

Fri May 31, 2013 7:32 am

I use a wireless connection for my pi. But i dont get my lan ip adress only the internet ip adress.

Code: Select all

/sbin/ifconfig wlan0
instead of

Code: Select all

/sbin/ifconfig eth0
doesn't show anything. Even the eth0 address doesnt show but it isn't connected.

Thanks.

idoodler
Posts: 13
Joined: Sun Apr 14, 2013 3:24 pm
Location: Bavaria/ Germany
Contact: Website

Re: Custom MOTD - Message of the Day

Thu Jun 06, 2013 7:21 pm

This looks great, but I have a little improvement for you, I think you like to have the memory in MB, not in KB, right? You can use

Code: Select all

free -t -m
to get this in terminal.

cditty
Posts: 31
Joined: Fri Sep 28, 2012 3:05 pm

Re: Custom MOTD - Message of the Day

Wed Jul 24, 2013 7:15 pm

Any suggestion on how to find out how much free space I'm using on an external drive?

cditty
Posts: 31
Joined: Fri Sep 28, 2012 3:05 pm

Re: Custom MOTD - Message of the Day

Tue Sep 10, 2013 8:48 pm

I've having a problem with this. I blew my pi away and redid it yesterday and now this won't run. I followed the details above but every time I run it, I get :no such file or directory.

I've even gone line by line and commented everything out except the very first line. I still get that error. I can cat the file and it shows what I expect, but running it gives the error.

I've lost.

alarrarte
Posts: 1
Joined: Fri Sep 13, 2013 9:35 pm

Re: Custom MOTD - Message of the Day

Fri Sep 13, 2013 9:37 pm

Thank you very much OP!!! found it very useful for my Pi!

Jamesking56
Posts: 13
Joined: Sat Oct 26, 2013 10:37 am
Location: Redditch, UK
Contact: Website

Re: Custom MOTD - Message of the Day

Sat Oct 26, 2013 8:07 pm

azeam wrote:If you fill in the information at http://netweather.accuweather.com/signu ... traveler=0 you will get the area code in a HTML snippet.

I followed the guide at http://www.mewbies.com/how_to_customize ... torial.htm to make a custom MOTD. The shorter version, including some minor differences for the Rpi, is remove the contents of

Code: Select all

/etc/motd
comment out

Code: Select all

uname -snrvm > /var/run/motd.dynamic
in

Code: Select all

/etc/init.d/motd
Change from "PrintLastLog yes" to

Code: Select all

PrintLastLog no
in

Code: Select all

/etc/ssh/sshd_config
Then

Code: Select all

sudo nano /etc/motd.tcl
add the following ugly but functional code

Code: Select all

#!/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 ""
}
Make the script executable

Code: Select all

sudo chmod 755 /etc/motd.tcl
and add

Code: Select all

/etc/motd.tcl
to the end of the file

Code: Select all

/etc/profile
The ascii art is made by user piksel and was taken from the link in the initial post.
ssh_login.jpg
How do I add the weather in your format?

sethfoxen
Posts: 1
Joined: Mon Oct 28, 2013 9:44 pm

Re: Custom MOTD - Message of the Day

Mon Oct 28, 2013 9:51 pm

I've always loved to have a custom MOTD, something that gave me a little information when I logged in, instead of that generic disclaimer. I've customized the script that azeam posted, but I'm having some problems. Mostly I just changed the ACII art, moved some description lines around, and removed a few.

Here's the text I'm saving into /etc/motd.tcl

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  # We have color support; assume it's compliant with Ecma-48
  # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  # a case would tend to support setf rather than setaf.)
  color_prompt=yes
    else
  color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to [email protected]:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\[email protected]\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

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)
          /\.-./\
          >_   _<       ______              ______
         / d\ /b \  ,   |  ___|             | ___ \ `date +"%A, %e %B %Y, %r"`
        /   / \   \);\  | |_ _____  ________| |_/ / `uname -srmo`$(tput setaf 1)
         `-.\Y/.-`.;;;| |  _/ _ \ \/ /______| ___ \/ _ \ '__| '__| | | |
           /   \ /;;;(  | || (_) >  <       | |_/ /  __/ |  | |  | |_| |
        _ | { } | _  `\ \_| \___/_/\_\      \____/ \___|_|  |_|   \__, |
       / \| `"` |/ \  |  Maintained by Seth Foxen                  __/ |
       |  | | | |  |  |  [email protected]                      |___/
       |  | | | |  | /   Uptime.............: ${UPTIME}
        ) | | | | (.'    Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
      _/  | |-| |  \_    CPU Temperature....: `exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"`
jgs  (((-') \ / \'-)))   Free Disk Space 2tb: `df -Pk | grep -E '^/dev/sda1' | awk '{ print $4 }' | awk -F '.' '{ print $1 }'`k on /dev/sda1 -- `df -Pk | grep -E '^/dev/sda1' | awk '{ print $5 }' | awk -F '.' '{ print $1 }'` of capacity
          `"" ""`        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`
$(tput sgr0)"
And the errors I'm getting when I logon
Last login: Mon Oct 28 17:31:09 2013 from ***.***.***.***
/etc/motd.tcl: line 5: return: can only `return' from a function or sourced script
/etc/motd.tcl: line 127: unexpected EOF while looking for matching ``'
/etc/motd.tcl: line 129: syntax error: unexpected end of file
[email protected] ~ $
I'm not entirely illiterate when it comes to coding, but it has been way too long since I've encountered these errors, and I can't seem to find anything wrong.

funtomas
Posts: 9
Joined: Mon Dec 02, 2013 10:12 am

Re: Custom MOTD - Message of the Day

Mon Dec 02, 2013 10:16 am

if you use lastlog -u $var(user) you will get current login time not previous

if you want correct time of last login you must use command: last -n2 $var(user) and than modify script

Roonix
Posts: 4
Joined: Sat Feb 15, 2014 4:44 pm

Re: Custom MOTD - Message of the Day

Sat Feb 15, 2014 4:55 pm

azeam wrote:If you fill in the information at http://netweather.accuweather.com/signu ... traveler=0 you will get the area code in a HTML snippet.

I followed the guide at http://www.mewbies.com/how_to_customize ... torial.htm to make a custom MOTD. The shorter version, including some minor differences for the Rpi, is remove the contents of

Code: Select all

/etc/motd
comment out

Code: Select all

uname -snrvm > /var/run/motd.dynamic
in

Code: Select all

/etc/init.d/motd
Change from "PrintLastLog yes" to

Code: Select all

PrintLastLog no
in

Code: Select all

/etc/ssh/sshd_config
Then

Code: Select all

sudo nano /etc/motd.tcl
add the following ugly but functional code

Code: Select all

#!/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 ""
}
Make the script executable

Code: Select all

sudo chmod 755 /etc/motd.tcl
and add

Code: Select all

/etc/motd.tcl
to the end of the file

Code: Select all

/etc/profile
The ascii art is made by user piksel and was taken from the link in the initial post.
ssh_login.jpg
Hmm could someone explain that last step to me please, how do I add /etc/motd.tcl to the end of /etc/profile? Thanks :)

wingloon
Posts: 4
Joined: Fri Jan 25, 2013 5:17 am

Re: Custom MOTD - Message of the Day

Thu Jul 24, 2014 6:07 am

startreksteve wrote:This site has a lot of region codes for Accuweather:
http://pastebin.com/dbtemx5F
Thanks for the link above. However, there is some fix for the location I need to use from below: -

City Name = "Kuala Lumpur, MY" Location = "ASI|MY|MY015|KUALA LUMPUR" Country = "Malaysia"

The working code is "ASI|MY|MY015|KUALALUMPUR"

Be careful of spacing...

qweluke
Posts: 5
Joined: Tue Jul 28, 2015 5:42 am

Re: Custom MOTD - Message of the Day

Tue Jul 28, 2015 12:48 pm

I don't know why but it won't works for me...
When I login via ssh I've got no colors and a static text instead of variables..
-> % ssh [email protected]
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l
#!/bin/sh

if [ -z ${1} ]; then
echo "Usage: ${0} {location of motd}"
exit 1
fi

if [ ${UID} -ne 0 ]; then
echo "This script must be runned with root privileges."
exit 1
fi

ip=`ip addr show scope global | grep inet | cut -d' ' -f6 | cut -d/ -f1`
up=`uptime | awk -F"up " '{print $2}' | awk -F"," '{print $1}'`
used=`df -h | grep 'dev/root' | awk '{print $3}'`
avail=`df -h | grep 'dev/root' | awk '{print $4}'`

echo "\033[0;32m
.~~. .~~.
'. \ ' ' / .'\033[0;31m
.~ .~~~..~. \033[0;37m _ _ \033[0;31m
: .~.'~'.~. : \033[0;37m ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_|\033[0;31m
~ ( ) ( ) ~ \033[0;37m | _| .'|_ -| . | . | -_| _| _| | | | . | |\033[0;31m
( : '~'.~.'~' : ) \033[0;37m |_| |__,|___| _|___|___|_| |_| |_ | | _|_|\033[0;31m
~ .~ ( ) ~. ~ \033[0;37m |_| |___| |_| \033[0;31m
( : '~' : )
'~ .~~~. ~'
'~'

\033[0;34m`hostname -f`
\033[1;30m${ip}
\033[1;34mUsed | Free
${used} | ${avail}
\033[1;30mUp. : ${up}
\033[0;30m" > ${1}

exit 0
Last login: Tue Jul 28 14:43:17 2015 from zxxxxxxx

TheExpertNoob
Posts: 1
Joined: Wed Jan 13, 2016 2:34 am

Re: Custom MOTD - Message of the Day

Wed Jan 13, 2016 2:46 am

So I had a MOTD that worked until I did a recent update/upgrade. Now it won't work. (just hangs on login)
did a 'bash --login -vvv' and it hangs on the line '/etc/motd.tcl'
I created a new motd2.tcl that just echos "Hello World" and had etc/profile point to the new one.
That now works, so I believe something has been broken in a recent update.

Here is my original MOTD code:

Code: Select all

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=0&locCode=NAM|US|AL|35803|" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'`
       '~'        Free Disk Space....: `df -Pm | grep -E '^/dev/root' | awk '{ print $4 }' | awk -F '.' '{ print $1 }'`Mb on /dev/root
$(tput sgr0)"
There is some line wrapping that occurs on the above code.
you can download the file druss.org/public/motd.tcl.

Return to “Beginners”