1

I have been using the Pi in an operating systems class this quarter and at the beginning of the quarter we set up our Pi's to email the IP address on boot up so we could just putty into the Pi's without hassle. I bought a new 32 gig card and in trying to set up the email script like I did the first time, I get an error with rc.local (the file I added the command to run the email program). If I manually type the command to run the email program it works just fine.

I hope I'm asking the right question but I'm still new to the Pi world.

picture of error

rc.local file contents:

#!/bin/sh -e 
# 
# rc.local 
# 
# This script is executed at the end of each multiuser runlevel. 
# Make sure that the script will "exit 0" on success or any other 
# value on error. 
# 
# In order to enable or disable this script just change the execution 
# bits. 
# 
# By default this script does nothing. 
# Print the IP address
_IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi

(sleep 10; python /home/pi/emailnotification.py)& 

exit 0
  • 2
    What are the contents of your rc.local file? – syb0rg Nov 16 '13 at 21:25
  • #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi (sleep 10; python /home/pi/emailnotification.py)& exit 0 – Bob Nov 17 '13 at 18:42
  • You should edit the contents into the question so they are more easily read. – syb0rg Nov 17 '13 at 19:36
  • Is the whole _IP=$(hostname -I) ... really on one line in your rc.local ? That'll throw an error – nos Nov 19 '13 at 17:06
1

As pointed out by @nos, your script has syntax errors. This line is wrong (having more than one error):

_IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi

You should probably change it to something like this:

_IP=$(hostname -I); if [ -n "$_IP" ]; then printf "My IP address is %s\n" "$_IP"; fi
0

Here is a great answer from the Ask Ubuntu community. The answer is very long (so I won't post it here) and a lot of work has been put into it. I would read all of it to get a full understanding of running commands from rc.local, then try the suggestions on how to fix it.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.