• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1376
  • Last Modified:

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?
0
spen_lang
Asked:
spen_lang
  • 5
  • 3
1 Solution
 
simon3270Commented:
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.
0
 
spen_langAuthor Commented:
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.
0
 
simon3270Commented:
Alternatively, are you telnetting into the machine as root or as another user? (I would guess, from the script you are calling, that you are logging in as "pi")  If it *is* "pi", you might want to have:

    su - pi -c "bash /home/pi/logon.sh"

in you /etc/rc.local file.  Even better, have:

    su - pi -c "bash /home/pi/logon.sh &"

so that the command goes into the background, and rc.local can get on with the rest of its work.
0
 
spen_langAuthor Commented:
Sadly - still not working :(
0
 
spen_langAuthor Commented:
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.
0
 
simon3270Commented:
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
0
 
spen_langAuthor Commented:
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 :)
0
 
spen_langAuthor Commented:
Thank you so much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now