Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Running Shell Script after boot on Raspberry PI

Posted on 2014-02-05
8
Medium Priority
?
1,228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 20

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 20

Accepted Solution

by:
simon3270 earned 2000 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 20

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

604 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