0

I used this page to try to run a shell script when the raspberry pi first turns on. This is the line I added at the bottom of the file(before exit 0):

sh /home/pi/alexa_start.sh &

I added the ampersand, as suggested by the webstie above, because my script is a continuous script that is supposed to start Amazon Alexa. This is the script:

#!/bin/sh
cd /home/pi
lxterminal -e sh ./alexa1.sh & sleep 3
lxterminal -e sh ./alexa2.sh & sleep 20
lxterminal -e sh ./alexa3.sh
lxterminal -e sh ./alexa4.sh

It runs 4 other scripts in separate terminal windows. Upon booting the pi, nothing happened. I tried using sudo in the rc.local file and it didn't help. Is the problem the lxterminal? How can I make this work?

EDIT:

I also tried adding this line @lxterminal -e /home/pi/alexa_start.sh to /etc/xdg/lxsession/LXDE-pi/autostart as suggested here, but that did not work either.

0

The answer below doesn't take into account that lxterminal requires the GUI to be up and running to succeed

One problem is most likely the "current working directory"

When you start

sh /home/pi/alexa_start.sh &

The current working directory is / - as the alexa?.sh scripts are in /home/pi, it's clear that ./alexa?.sh won't exist

edit /home/pi/alexa_start.sh as follows

#!/bin/sh
cd /home/pi
lxterminal -e sh ./alexa1.sh & sleep 3
... etc

I assume alexa?.sh etc are in /home/pi

Alternatively, add the /home/pi to the path of the script

#!/bin/sh
lxterminal -e sh /home/pi/alexa1.sh & sleep 3
lxterminal -e sh /home/pi/alexa2.sh & sleep 20
lxterminal -e sh /home/pi/alexa3.sh
lxterminal -e sh /home/pi/alexa4.sh

The difference between the two answers is what the current directory will be in the alexa?.sh scripts - in the first answer it will be /home/pi - in the second it will be whatever it was when rc.local ran the start script (again, most likely / - but I wouldn't count on anything at this point)

Note: in either case, the alexa?.sh scripts will be running as root. If the alexa scripts need to be run as a user other that root, say as user pi then change the command in rc.local to

su pi -c '/home/pi/alexa_start.sh &'

or even

su pi -l -c '/home/pi/alexa_start.sh &'

the -l would mean you don't need to make the path "changes" above, as this will be done for you. The -l argument Provides an environment similar to what the user would expect had the user logged in directly

  • I added cd /home/pi to my alexa_start script and nothing happened. This is what my rc.local looks like now: python3 /home/pi/shutdown.py & sh /home/pi/alexa_start.sh & When I booted the PI, I was brought to the GUI without any lxterminal windows open. – Nick Solonko Apr 29 '17 at 0:29
  • oh ... lxterminal relies on GUI being active ... that's yet another problem - you need to wait for the GUI to be running before running lxterminal – Jaromanda X Apr 29 '17 at 0:33
  • to wait for GUI, one method is to use systemd and create your script above as a service, that waits for display-manager.service – Jaromanda X Apr 29 '17 at 0:43
0

Add this stuff to /home/pi_h/.config/lxsession/LXDE-pi/autostart

@/usr/bin/lxterminal -e sh /home/pi/alexa1.sh & sleep 3
@/usr/bin/lxterminal -e sh /home/pi/alexa2.sh & sleep 20
@/usr/bin/lxterminal -e sh /home/pi/alexa3.sh
@/usr/bin/lxterminal -e sh /home/pi/alexa4.sh

That autostart file gets run as soon as you login (or get auto logged in) to the GUI

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.