droidus
Posts: 253
Joined: Sat Feb 02, 2013 4:09 am

PI MOTD

Wed May 08, 2013 10:45 pm

I am trying to create a Pi MOTD message when a user logs in. I have the following code:

Code: Select all

#!/bin/bash
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 {'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:/   '~ .~~~. ~'    Weather............: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=EUR|UK|UK001|NAILSEA|" | sed -n '/Currently:/ s       '~'
$(tput sgr0)"
When I log in on the pi, it just shows the code.

SimonSmall
Posts: 220
Joined: Tue Oct 09, 2012 8:13 pm

Re: PI MOTD

Thu May 09, 2013 7:21 pm

I think you misunderstand the MOTD (message of the day). It shows the text of the motd file (hence shows your code)

I think you want to run your script after the boot has completed. Is that so?

User avatar
tedhale
Posts: 114
Joined: Thu Sep 20, 2012 4:52 pm
Location: Williamsburg, VA, USA
Contact: Website

Re: PI MOTD

Thu May 09, 2013 7:28 pm

if you put that code at the end of /etc/bash.bashrc it will be run every time someone logs in.

(Or is it every time a bash shell runs? That might not be what you want.)
- Ted B. Hale
http://raspberrypihobbyist.blogspot.com

Return to “Beginners”