jaydeecorp13
Posts: 1
Joined: Fri Jan 22, 2016 10:58 pm

Re: Custom MOTD - Message of the Day

Fri Jan 22, 2016 11:11 pm

Don't think it's been mentioned yet, the regex that gets the weather doesn't account for negative temps, so when it's negative no result comes up. Add that in for an easy fix, i.e. change \([0-9]*\) to \(-\?[0-9]*\). Just throwing that out there. ;)

User avatar
startrek.steve
Posts: 383
Joined: Thu Aug 30, 2012 7:19 pm

Re: Custom MOTD - Message of the Day

Thu Feb 18, 2016 8:04 pm

yanewby wrote:
hop wrote:This looks great, I will be using this OP thanks!
I'm glad you like it and I hope you find it useful. If you can think of anything else you'd like reported on this screen, let me know and I will see if I can work out how to include it.

I have since added a "Free Disk Space" entry to my screen with the addition of this code:

Code: Select all

Free Disk Space....: `df -Pk | grep -E '^/dev/sda1' | awk '{ print $4 }' | awk -F '.' '{ print $1 }'`k on /dev/sda1
I've been using this for quite a while on my two wheezy installs, but it doesnt seem to work on Jessie on my Zero?

Steve
Pi 2 running LibreElec Krypton, Pi 2 running Wheezy Desktop, Pi 1 headless Wheezy, downloading Radio, Pi 1 running Picore headless Media Server, Pi Zero to be an Old Time Radio Project. Pi 3 testing. Pi Zero W downloading Radio shows headless.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Custom MOTD - Message of the Day

Thu Feb 18, 2016 9:38 pm

startrek.steve wrote:
I've been using this for quite a while on my two wheezy installs, but it doesnt seem to work on Jessie on my Zero?

Steve
I think Debian changed the motd, so some of it no longer works with Jessie. What I did was move it to ".bash_profile" since I was using colors and a two line prompt anyway (user, host, and path on one line, prompt on next line). Plus you can include anything else you like if you're putting it in "bash_profile". Now I just use the "motd" to show my SDCard number, size, and the static IP addresses that are set on that card.

Code: Select all

Using username "jimmy".
Authenticating with public key "rsa-key-20151018"

        Raspbian -  SD Card #5  8 gig    rpi3 192.168.0.8
                                         rpi3 192.168.0.9 Wireless

Last login: Thu Feb 18 08:08:55 2016 from 192.168.0.4

Linux rpi3 4.1.17+ #838 Tue Feb 9 12:57:10 GMT 2016 armv6l GNU/Linux

Filesystem                    Type  Size  Used Avail Use% Mounted on
/dev/root                     ext4  7.2G  3.4G  3.5G  50% /
//192.168.0.98/Network Folder cifs  1.8T  302G  1.4T  19% /home/jimmy/network-folder
//192.168.0.3/Downloads       cifs  993G  380G  614G  39% /home/jimmy/win7-folder
/dev/mmcblk0p1                vfat   56M   20M   37M  36% /boot


             total       used       free     shared    buffers     cached
Mem:           371        165        206          4         21         81
Swap:           24          0         24


 [email protected] rpi3: ~
>$

User avatar
startrek.steve
Posts: 383
Joined: Thu Aug 30, 2012 7:19 pm

Re: Custom MOTD - Message of the Day

Fri Feb 19, 2016 7:43 am

OK thats the output, what do I need in the script to get this?
JimmyN wrote:
startrek.steve wrote:
I've been using this for quite a while on my two wheezy installs, but it doesnt seem to work on Jessie on my Zero?

Steve
I think Debian changed the motd, so some of it no longer works with Jessie. What I did was move it to ".bash_profile" since I was using colors and a two line prompt anyway (user, host, and path on one line, prompt on next line). Plus you can include anything else you like if you're putting it in "bash_profile". Now I just use the "motd" to show my SDCard number, size, and the static IP addresses that are set on that card.

Code: Select all

Using username "jimmy".
Authenticating with public key "rsa-key-20151018"

        Raspbian -  SD Card #5  8 gig    rpi3 192.168.0.8
                                         rpi3 192.168.0.9 Wireless

Last login: Thu Feb 18 08:08:55 2016 from 192.168.0.4

Linux rpi3 4.1.17+ #838 Tue Feb 9 12:57:10 GMT 2016 armv6l GNU/Linux

Filesystem                    Type  Size  Used Avail Use% Mounted on
/dev/root                     ext4  7.2G  3.4G  3.5G  50% /
//192.168.0.98/Network Folder cifs  1.8T  302G  1.4T  19% /home/jimmy/network-folder
//192.168.0.3/Downloads       cifs  993G  380G  614G  39% /home/jimmy/win7-folder
/dev/mmcblk0p1                vfat   56M   20M   37M  36% /boot


             total       used       free     shared    buffers     cached
Mem:           371        165        206          4         21         81
Swap:           24          0         24


 [email protected] rpi3: ~
>$
Pi 2 running LibreElec Krypton, Pi 2 running Wheezy Desktop, Pi 1 headless Wheezy, downloading Radio, Pi 1 running Picore headless Media Server, Pi Zero to be an Old Time Radio Project. Pi 3 testing. Pi Zero W downloading Radio shows headless.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Custom MOTD - Message of the Day

Fri Feb 19, 2016 11:22 am

This is the ".bash_profile" script that I use.

Code: Select all

echo ""
uname -a
echo ""
df -hT --exclude-type=rootfs --exclude-type=tmpfs --exclude-type=devtmpfs
echo ""
echo ""
free -mo
echo ""

Decoration1="\n\[\e[91m\]"
RegularUserPart="\n\[\e[1;92m\] \u"
RootUserPart="\[\e[31;5m\]\u\[\e[m\]"
Between="\[\e[1;92m\]@ "
HostPart="\[\e[93;1m\]\h: "
PathPart="\[\e[93;1m\]\w"
Decoration2="\[\e[1;91m\]\n>\[\e[m\]"
case `id -u` in
   0) export PS1="$Decoration1$RootUserPart$Between$HostPart$PathPart$Decoration2# ";;
   *) export PS1="$RegularUserPart$Between$HostPart$PathPart$Decoration2$ ";;
esac

export PATH=$PATH:/home/jimmy/scripts

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
Here is a little description in case you want to edit things.
The "echo" commands are used to add a blank line between the sections to make it easier to read.
The "df" command shows disk space without all the "tempfs" stuff, which I don't need to see.
The "free -mo" just shows mem and swap without the buffer and cache lines.

Everything from "Decoration1" down to "esac" is the colored two line prompt. The prompt when logged in as root is different from the user prompt.
"Decoration1" drops down a line before printing the prompt and sets color. You really don't need to set the color to white at that point, but it's a remnant from my earlier prompt versions and does no harm.
"RegularUserPart" and "RootUserPart" sets the username color and prompt (# or $).
"Between" sets the color of the "@"
"HostPart" sets the color of the hostname
"PathPart" sets the color of the path
"Decoration2" drops down to the second line, sets the prompt color and prints the prompt, then sets the text color back to white so commands typed and following text will be white. When you set a color it stays until you change it, so that sets things back to normal after the colored prompt.

I like the two line prompt as it provides a full line for the path, sometimes it's pretty long. Then it drops down and provides a full line for the command underneath the path, so long commands usually don't have to "wrap" to the next line.

The export lines put it all together for the root or user prompt, you can re-order the individual parts, add more, etc. The custom prompt works whether you're using LXTerminal or connecting with Putty.

The motd is just a manual edit of "motd" that I do when I set the card up. I number each card with a fine tip silver colored Sharpie, and I have an index file for all my cards with a description of what's on each. Each uses different IP's so I can shuffle cards around among the Pi's and I don't have to worry about two of them having the same address. If I look in my index and see that card #3 has what I want I can plug it in and already know what the IP address will be. But that's just my method, I tend to be a little OCD sometimes when it comes to organization of things like that.

sleepgoing
Posts: 3
Joined: Fri Feb 19, 2016 4:16 pm

Re: Custom MOTD - Message of the Day

Fri Feb 19, 2016 4:21 pm

Hi there, I tried the code supplied and after that i got no more color on my ssh sessions.

I have the code on /home/pi/.bash_profile
I checked the bashrc file and I got it set for "auto" on the color strings but still only got the MOTD with color.

Can anyone please helpe me with this?

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Custom MOTD - Message of the Day

Fri Feb 19, 2016 9:25 pm

So you don't have color when you had it before, such as when using "ls", "dir", or something like "dmesg"?

sleepgoing
Posts: 3
Joined: Fri Feb 19, 2016 4:16 pm

Re: Custom MOTD - Message of the Day

Fri Feb 19, 2016 10:10 pm

JimmyN wrote:So you don't have color when you had it before, such as when using "ls", "dir", or something like "dmesg"?
Yes, I did use to have color on everything, even the prompt ([email protected]) used to be green now it is all white and I did not manage to get it back working in color.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Custom MOTD - Message of the Day

Fri Feb 19, 2016 10:21 pm

That's strange, mine is of course in color and works the same in LXTerminal or Putty. The script I posted doesn't change anything permanently, if you remove it from your .bash_profile you should be back to where you were after logging in again.

sleepgoing
Posts: 3
Joined: Fri Feb 19, 2016 4:16 pm

Re: Custom MOTD - Message of the Day

Mon Feb 22, 2016 8:28 am

JimmyN wrote:That's strange, mine is of course in color and works the same in LXTerminal or Putty. The script I posted doesn't change anything permanently, if you remove it from your .bash_profile you should be back to where you were after logging in again.
Nevermind, had to reinstall the server due to a boot sector failure, will try again next time.

The_PI_Guy
Posts: 4
Joined: Sun Jan 17, 2016 4:06 am

Re: Custom MOTD - Message of the Day

Mon Feb 29, 2016 9:22 pm

Yeah so just creat a new .bash_profile in the directory stated (home/pi/) and also remove anything in the /etc/motd

acalanum
Posts: 1
Joined: Fri Mar 11, 2016 4:49 pm

Re: Custom MOTD - Message of the Day

Fri Mar 11, 2016 4:50 pm

Hi, I'm new to Linux and just got a raspberry pi. I have implemented this MOTD - thanks btw - but I am wondering if I can add a forecast to this as well. Like today's and tomorrow's forecast. Has anyone done this?

Blyzz
Posts: 7
Joined: Thu Jan 22, 2015 7:42 am

Re: Custom MOTD - Message of the Day

Wed Mar 16, 2016 3:27 pm

Just a heads-up. Had a bit of a pain getting the weather for Cape Town - had to use HTML escape character for space "%20" now it works a charm.
Thanks for this!
PS: here's the weather for CPT people:

Code: Select all

Weather............: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=AFR|ZA|SF011|CAPE%20TOWN" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*$

K1LLUM1N471
Posts: 1
Joined: Tue Apr 05, 2016 7:35 am

Re: Custom MOTD - Message of the Day

Tue Apr 05, 2016 8:56 am

Additional information for other locales than English (us_US):

You should add

Code: Select all

unset LANG
at the beginning of your script. Otherwise the command

Code: Select all

/bin/grep "inet addr"
won't return the local IP, because e.g. in German the search pattern is "inet Adresse".

At the end of your script you can also add

Code: Select all

export LANG="de_DE.UTF-8"
to reset your locales back (here: de_DE.UTF-8 for German).

Kind regards,
K1LLUM1N471

Sturmkater
Posts: 15
Joined: Mon Jun 02, 2014 5:39 pm

Re: Custom MOTD - Message of the Day

Thu Jun 16, 2016 2:26 pm

Solved: Sorry, I just had to install tcl :roll: :oops:

Thanks a lot for thous nice imputs. Sadly i'm getting an error with this one:
/usr/bin/env: tclsh: No such file or directory
maybe I need to install tclsh? But if yes, whitch one?

Code: Select all

Package tclsh is a virtual package provided by:
  tcl8.4 8.4.20-1
  tcl 8.6.0+8+b1
You should explicitly select one to install.
E: Package 'tclsh' has no installation candidate
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

S0litaire
Posts: 216
Joined: Thu Dec 29, 2011 4:24 pm
Location: Ayrshire, Scotland
Contact: ICQ Skype Twitter

Re: Custom MOTD - Message of the Day

Mon Feb 13, 2017 12:05 am

Hi
I've gotten around to customizing the MOTD. and here's my experience...

The AccuWeather format has changed and can't get a close enough city from the old list of RSS feeds to be of any use. So as I'm in the UK, I've decided to use the BBC Weather RSS feed instead.

They provide 2 free feeds :
"3 day forecast" Updated twice a day
and
"current observations" UK updated every hour / International updated every 3 hours

More info here: https://support.bbc.co.uk/platform/feed ... rFeeds.htm

They are xml feeds and they have a fixed structure but the naming isn't great.

I'll be using the "current observations" feed.
Example:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" version="2.0">
  <channel>
    <atom:link href="http://open.live.bbc.co.uk/weather/feeds/en/####/observations.rss" rel="self" type="application/rss+xml" />
    <title>BBC Weather - Observations for  ####, United Kingdom</title>
    <link>http://www.bbc.co.uk/weather/####</link>
    <description>Latest observations for #### from BBC Weather, including weather, temperature and wind information</description>
    <language>en</language>
    <copyright>Copyright: (C) British Broadcasting Corporation, see http://www.bbc.co.uk/terms/additional_rss.shtml for more details</copyright>
    <pubDate>Sun, 12 Feb 2017 22:49:08 +0000</pubDate>
    <item>
      <title>Sunday - 22:00 GMT: Thick Cloud, 4°C (39°F)</title>
      <link>http://www.bbc.co.uk/weather/****</link>
      <description>Temperature: 4°C (39°F), Wind Direction: East North Easterly, Wind Speed: 9mph, Humidity: 84%, Pressure: 1030mb, Falling, Visibility: Very Good</description>
      <pubDate>Sun, 12 Feb 2017 22:49:08 +0000</pubDate>
      <guid isPermaLink="false">http://www.bbc.co.uk/weather/****-2017-02-12T22:49:08.000Z</guid>
      <georss:point> ##.## ##.##</georss:point>
    </item>
  </channel>
As you can see the actual weather information is in the second <description> tags, which is also used by the title "Latest observations for..." So a simple "grep" didn't work in the MOTD script.

So i decided to pull that bit out of the MOTD script and try to get a simple text file of the Weather descriptions first then use that in the MOTD.
This is the ugly script which runs as a cron job every 2 hours:

Code: Select all

#!/bin/bash
rm /home/pi/tmp/Weather
rm /home/pi/tmp/weather.rss
wget -O /home/pi/tmp/weather.rss http://open.live.bbc.co.uk/weather/feeds/en/####/observations.rss
grep -E -m 1 -o "<description>T(.*)</description>" /home/pi/tmp/weather.rss | sed -e 's,.*<description>\([^<]*\)</description>.*,\1,g' > /home/pi/tmp/Weather
The first 2 lines remove old files (not sure if needed but it helps me to see if the script actually works)
The next line grabs the RSS xml from the BBC Weather site (change the #### to the first half of your postcode if you're in the UK) and saves it in a tmp folder as "weather.rss"

If you're outside the UK then go here: http://www.bbc.co.uk/weather/ and enter your location in the search box.
example: for "New York, USA" this is the page you'll get http://www.bbc.co.uk/weather/5128581. Use the 7 numbers instead of the "####" and you'll get the rss feed for New York.

The first part of the 4th line :

Code: Select all

 grep -E -m 1 -o "<description>T(.*)</description>" /home/pi/tmp/weather.rss 
does a rough cut extracting everything between the second <description> tag from the "weather.rss" file.
As their are 2 tags like this I had to use "<description>T", as the second usage always begins with "Temperature" so this was a quick and dirty way of getting the correct information.
This will give you the following :

Code: Select all

<description>Temperature: 4°C (39°F), Wind Direction: East North Easterly, Wind Speed: 9mph, Humidity: 84%, Pressure: 1030mb, Falling, Visibility: Very Good</description>

As you see it does not look nice with those 2 tags so this is where the next part comes in:

Code: Select all

 sed -e 's,.*<description>\([^<]*\)</description>.*,\1,g' 
This cuts out the 2 tags which makes it nicer to look at.

Code: Select all

Temperature: 4°C (39°F), Wind Direction: East North Easterly, Wind Speed: 9mph, Humidity: 84%, Pressure: 1030mb, Falling, Visibility: Very Good 
The last bit saves the tidy output to a text file called "Weather".

Then all i need to do is add the following line with the other "set" variables in the /etc/motd.tcl script :

Code: Select all

 set Weather [exec -- cat /home/pi/tmp/Weather] 
and call the variable "Weather" in the display section of /etc/motd.tcl:

Code: Select all

puts "   Weather.......: $Weather"
I've done a bit of pruning of the original display, but this is what it looks like using the BBC Weather information :

Code: Select all

You have new mail.
Last login: Sun Feb 12 22:54:51 2017 from rapsberry.home

         .~~.   .~~.
        '. \ ' ' / .'
         .~ .~~~..~.                      _                          _
        : .~.'~'.~. :     ___ ___ ___ ___| |_ ___ ___ ___ _ _    ___|_|
       ~ (   ) (   ) ~   |  _| .'|_ -| . | . | -_|  _|  _| | |  | . | |
      ( : '~'.~.'~' : )  |_| |__,|___|  _|___|___|_| |_| |_  |  |  _|_|
       ~ .~ (   ) ~. ~               |_|                 |___|  |_|   
        (  : '~' :  )
         '~ .~~~. ~'
             '~'
   System........: Linux, raspberry, 4.4.38-v7+, #938, SMP
   Uptime........: 13days 4hours 45minutes 1seconds
   Temperature...: 36.5°C
   Load..........: 0.94 (1minute) 0.76 (5minutes) 0.60 (15minutes)
   Memory MB.....: Total: 973  Used: 903  Free: 69  Cached: 766  Swap: 50
   Processes.....: You're running 8 which makes a total of 144 running
   Weather.......: Temperature: 3°C (37°F), Wind Direction: North Easterly, Wind Speed: 8mph, Humidity: 85%, Pressure: 1031mb, Rising, Visibility: Very Good
[email protected]:~ $
Might take another look at tidying up the script, their are a few pearl / python scripts that should be able to do this a lot easier, but i'm useless at programming, so copy/paste from google searches is fine for me! ;)
--
Laters

Bill "Solitaire" C

Anáil nathrach, ortha bhas betha, do cheol déanta

nachoparker
Posts: 16
Joined: Mon Feb 20, 2017 8:39 am

Re: Custom MOTD - Message of the Day

Thu Apr 06, 2017 3:14 pm

Hi, I wrote an up to date guide for creating dynamic MOTD in Raspbian.

It explains the role of each file such as /var/run/motd and why some of them do not work anymore.

Image

I hope it helps

https://ownyourbits.com/2017/04/05/cust ... nd-ubuntu/

ScheissSchiesser
Posts: 9
Joined: Wed Mar 23, 2016 2:48 pm

Re: Custom MOTD - Message of the Day

Mon Apr 17, 2017 3:19 am

Hey y'all,

I had added the following code to my /home/pi/.profile

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 wlan0 | /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|NY|ROCHESTER|" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'`
       '~'        Free Disk Space....: `df -Pk | grep -E '^/dev/root' | awk '{ print $4 }' | awk -F '.' '{ print $1 }'`k on /dev/root
$(tput sgr0)" 
I then decided I wanted to install xorg and PIXEL and tried to use `startx` to start my xsession. My desktop would try to start, and then quit back to the command line, with no obvious errors. After about an hour of deciphering the xorg log, I noticed the /home/pi/.xsession-errors file, and had a look (in retrospect, I probably should I have looked at that sooner!):

Code: Select all

Xsession: X session started for pi at Sun Apr 16 22:24:43 EDT 2017
localuser:pi being added to access control list
/etc/X11/xinit/xinitrc: 24: /home/pi/.profile: let: not found
/etc/X11/xinit/xinitrc: 25: /home/pi/.profile: arithmetic expression: expecting primary: "%60"
I saw this and didn't think much of it the first time, but I came across another thread where the user was able to run `sudo startx` but not `startx`, so I tried it. Lo and behold, it worked! But of course, we don't want our XSession running with root privileges.

But that got me thinking about the .profile issue... the root user would ignore .profile when starting a shell. Perhaps that message in the error log was not extraneous ("yeah, no shit!" said everyone in the thread at once.) I removed the entirety of that MOTD code above and I am now typing this from my PIXEL desktop.

This was a rather long-winded way to let y'all know that for whatever reason, that MOTD code is not liked by xorg/xsession/PIXEL or what-have-you. Hopefully someone else having issues with startx sees this post before spending hours ignoring an error message...

In order to use that MOTD message, perhaps it could be placed in .bash_profile or .bashrc instead of .profile. Does xorg/xsession use either of those files? Otherwise, the MOTD code would have to be reworked to fix the error.

Thank you for providing the MOTD code, BTW. I enjoyed my custom message for months before deciding to install a DE :D

RamSet
Posts: 1
Joined: Wed May 31, 2017 8:54 pm

Re: Custom MOTD - Message of the Day

Wed May 31, 2017 9:06 pm

After about 2 weeks of adapting code for my situation:
mpi.png
mpi.png (29.54 KiB) Viewed 2824 times
Full screen view:
download/file.php?id=18959


Monitoring for 2 APC UPS and VPN sessions, last login and bad password attempts.

Language is Romanian .

macoh59
Posts: 2
Joined: Sat Jun 30, 2018 11:16 am

Re: Custom MOTD - Message of the Day

Sat Jun 30, 2018 11:21 am

Hello Everyone,

I love this and actually got it working in my .bashrc file. However I am in the United States and we go by Fahrenheit instead of celsius How do I fix that one the following line:

curl -s "http://rss.accuweather.com/rss/liveweat ... 01|NAILSEA[/b]| I know this is where I need to fix it but what are the correct settings?

Thanks Guys,

macoh59
Posts: 2
Joined: Sat Jun 30, 2018 11:16 am

Re: Custom MOTD - Message of the Day

Sat Jun 30, 2018 7:37 pm

startreksteve wrote:
Tue Nov 27, 2012 9:00 am
Got it!

curl -s "http://rss.accuweather.com/rss/liveweat ... -UPON-HULL|" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'

Delivers: 45°F, Mostly Cloudy W/ Showers
Change metric=1 to metric=0 for Farenheit
Dunno what UK001 does because whatever you change it to it still gives the same output.
Steve
Thanks for this didn't see it my first time around.

Raceman
Posts: 25
Joined: Thu Jul 03, 2014 10:07 pm

Re: Custom MOTD - Message of the Day

Mon Jul 09, 2018 6:05 pm

Not working the Ip part of the script
`/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`

For the first part it gives an empty record, the second part works.

User avatar
DougieLawson
Posts: 35343
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Custom MOTD - Message of the Day

Mon Jul 09, 2018 6:16 pm

Try
/sbin/ifconfig eth0 | /usr/bin/awk '/inet .*broadcast/ {print $2}'
as the output of ifconfig changed with stretch.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Raceman
Posts: 25
Joined: Thu Jul 03, 2014 10:07 pm

Re: Custom MOTD - Message of the Day

Mon Jul 09, 2018 9:52 pm

DougieLawson wrote:
Mon Jul 09, 2018 6:16 pm
Try
/sbin/ifconfig eth0 | /usr/bin/awk '/inet .*broadcast/ {print $2}'
as the output of ifconfig changed with stretch.
Simply perfect. Thank you very much.

Raceman
Posts: 25
Joined: Thu Jul 03, 2014 10:07 pm

Re: Custom MOTD - Message of the Day

Mon Jul 09, 2018 10:07 pm

TheExpertNoob wrote:
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.

How to include SSH logins in this MOTD?

Return to “Beginners”