Solved

Running Shell Script after boot on Raspberry PI

Posted on 2014-02-05
8
1,070 Views
Last Modified: 2016-08-13
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
Comment
Question by:spen_lang
  • 5
  • 3
8 Comments
 
LVL 19

Expert Comment

by:simon3270
ID: 39835486
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
 

Author Comment

by:spen_lang
ID: 39835502
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
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 39835514
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
 

Author Comment

by:spen_lang
ID: 39835576
Sadly - still not working :(
0
 

Author Comment

by:spen_lang
ID: 39835589
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
 
LVL 19

Expert Comment

by:simon3270
ID: 39835619
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
 

Author Comment

by:spen_lang
ID: 39835964
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
 

Author Closing Comment

by:spen_lang
ID: 39835966
Thank you so much!
0
Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question