Not sure if this has been answered as I'm not really sure what to search for... (beginner with Raspberry Pi)

My idea was to copy a file from a flash disk to the pi and then execute, reason being I want to be able to update the file without going into the pi.

This might not be the best method but it works...

Created an extra file with the following and called the file from rc.local


sleep 30
cp /media/pi/drive/file.sh /home/pi
sudo chmod +x /home/pi/file.sh

I know the file.sh was executed but it's not executed in a window, therefor cannot see what's going on in the program, is there a way to change my code to launch in a new terminal so that it doesn't run in the background? Not using any fancy terminals, just the stock standard one.

  • It is unclear what you are ACTUALLY trying to do. One thing is; anything executed by rc.local (if it runs at all) is run by root so you don't need sudo. rc.local is obsolete on a systemd OS. You are unlikely to have ANYTHING mounted in /media at boot time.
    – Milliways
    Commented Jun 5, 2019 at 7:57
  • the piece of code works, copies the file from the flash to /home/pi and executes it, just don't want it to run in the background but rather in a window as if I started the file from terminal Commented Jun 5, 2019 at 8:06
  • If the delay is long enough, and you boot to GUI it MAY be mounted before the copy if you are lucky. systemd runs startup code (including rc.local) asynchronously, which is why it is unreliable. Any output is owned by root, and would appear on the startup console.
    – Milliways
    Commented Jun 5, 2019 at 8:11
  • don't know any better way but (maybe by luck) it works :) just now need to figure out how to auto open a window and execute the file.sh Commented Jun 5, 2019 at 8:16
  • If it works, why do you want to open a console window? Do you need any manual interaction?
    – Ingo
    Commented Jun 5, 2019 at 14:57

1 Answer 1


As pointed out in comments, using rc.local is not ideal as it might be running too soon for the flash disk to be mounted; almost definitely too soon to do anything on the GUI and is not the supported way of doing things since the move to SystemD anyway.

Maybe a better way would be to have a file at /etc/xdg/autostart/99-AutoCopy.desktop, something like:


This should run your script in a terminal window each time you login to the GUI. You may also like to alter your script a little to check the file is there before copying it and maybe pause at the end so you can see the result in the terminal: as it is the window would close pretty quickly.


#sleep 30
if [ -e /media/pi/drive/file.sh ]; then
 cp /media/pi/drive/file.sh /home/pi/
 sudo chmod +x /home/pi/file.sh
 read -p "No script found, press ENTER."
  • 1
    Hi, made the file exactly as you typed, even the same 99- filename, doesn't execute. do I need to do something to make sure it's executed? Commented Jun 5, 2019 at 14:32
  • Hello. Not that I'm aware of: should just work. That said, it wouldn't do any harm to make the desktop file executable. Also, is the script location correct and executable? Commented Jun 5, 2019 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.