Solved

Running Shell Script after boot on Raspberry PI

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

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now