Link to home
Start Free TrialLog in
Avatar of spen_lang
spen_lang

asked on

Running Shell Script after boot on Raspberry PI

I'm making a web kiosk display board using a raspberry pi and I want to send some key strokes to the browser window 2 minutes after it's loaded. The script sends the logon details for a webserver.

I've got a script that sends the keystrokes which works fine from the telnet console:
#!/usr/bash
username="username"
password="password"
echo "Setting Display"
export DISPLAY=:0
echo "Sending Username"
for char in $(sed -E s/'(.)'/'\1 '/g <<<"$username"); do
    xdotool key $char
done
xdotool key Tab
echo "Sending Password"
for char in $(sed -E s/'(.)'/'\1 '/g <<<"$password"); do
    xdotool key $char
done
xdotool key Return
echo "Waiting 5 Seconds"
sleep 5
echo "Setting Remember Password"
xdotool key Tab
xdotool key Tab
xdotool key Return
echo "Finished"

Open in new window


I've tried to add
bash /home/pi/logon.sh

Open in new window

to the rc.local file - but it doesn't send the keystrokes to the browser?

Does any one know why that would be? As I say - it works fine from the telnet window if I run the script, but it doesn't work when run from boot.

I had
sleep 120

Open in new window

on the line before it to stop if firing right away and wait until the browser has loaded - and I know the script is running from rc.local, because when I remove the sleep command, I see the echos from the script.

Any ideas?
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Is "xdotool" in /bin or /usr/bin (or their sbinequivalents)?  if not, you need to put the full path to it in the script wherever it is called.
Avatar of spen_lang
spen_lang

ASKER

xdotool is in /usr/bin/xdotool

I may still try to put the full path to it in the script to see if it works.
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sadly - still not working :(
You are right though - I'm running the script as pi...

I'm going to add an echo to a file to prove the script both start and finishes... I shall report back.
Add
  exec >/tmp/tstecho.out 2>&1
  set -x
to the start of your script, to log every command before it is run, and to capture any errors
WOO HOO!! It's working!

You were right earlier saying that I needed to run it as the user pi and n the background...
the reason it didn't work was because I copied your code from here into the pi - and you had typed logon.sh but the script is login.sh

Once I realised - it's working lovely!


Thank you :)
Thank you so much!