2

I recently bought a Raspberry Pi, and have started playing around with it. After changing my MOTD, (to include colours), the colour codes are coming up as raw-text instead of executing.

I am connected to my Raspberry Pi via SSH in a Mac Terminal. I also tried directly via the Raspberries command line. How do I allow colour?

Below is a screenshot of the failed MOTD:

MOTD Colour Error

The file I am editing is "/etc/motd". I am editing it with "nano".

Code below:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

#!/bin/bash
echo "$(tput setaf 2)
   .~~.   .~~.
  '. \ ' ' / .'$(tput setaf 1)
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) $(tput sgr0)Raspberry Pi$(tput setaf 1)
   '~ .~~~. ~'
       '~'
$(tput sgr0)"
  • 2
    motd is a text file read by login. You can't run a script in it. – fd0 Aug 18 '15 at 10:36
  • Can you paste the code instead of an image? That makes it much easier to help you. – klimpergeist Aug 18 '15 at 10:37
  • @fd0 I had a feeling someone would say that... Is there a way I can execute a scripted file upon connection? – user129109 Aug 18 '15 at 10:38
  • @klimpergeist Exactly the same. Updated for you. – user129109 Aug 18 '15 at 10:39
  • 1
    @FinnRayment A cron or systemd job should do the trick. There you can execute arbitrary scripts at a given time or on startup. – klimpergeist Aug 18 '15 at 10:40
4

Due to the fact that "etc/motd" is a plain text file, commands are not executed, but instead printed as so:

#!/bin/bash
echo "$(tput setaf 2)
   .~~.   .~~.
  '. \ ' ' / .'$(tput setaf 1)
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) $(tput sgr0)Raspberry Pi$(tput setaf 1)
   '~ .~~~. ~'
       '~'
$(tput sgr0)"

Instead, create a new file called "motd.sh" inside "/etc" and input the MOTD there instead. This is now an executable script, but is not executed. So goto "/etc/profile" and add at the end of the file:

bash /etc/motd.sh

This will now execute the script upon connection and display colour.

   .~~.   .~~.
  '. \ ' ' / .'
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) Raspberry Pi
   '~ .~~~. ~'
       '~'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy