Solved

Running Shell Script after boot on Raspberry PI

Posted on 2014-02-05
8
1,086 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

Suggested Solutions

Title # Comments Views Activity
AWS Central Authentication 1 87
Bash script - Exit out of choice loop 2 44
EXCHANGE. LINUX, SYMANTEC MESSAGING GATEWAY 2 38
The better OS Architecture 13 66
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

837 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