How to Run a Script on Startup for Raspberry Pi // EASY

preview_player
Показать описание
This video shows how to run a script on your Raspberry Pi when it is powered on. Let me know if you have any questions!

I may earn commission if you purchase from the links above

Here are timestamps and steps:
0:00 Intro
0:26 Testing the script
1:28 Initializing crontab
Command: sudo crontab -e
Enter password if requested
Select option 1 to enter into the Nano editor
1:52 Edit crontab
@reboot ~Your command here~ &
**Don't forget the ampersand**
2:32 Testing
2:46 Outro

Рекомендации по теме
Комментарии
Автор

Helped me; might help others. If it works in the command tab and not as a cron job, it might be trying to run before dependencies are available. You can give the pi time to first fully boot by delaying the script to run 30 seconds later as follows:

@reboot sleep30; python3 home/pi/Desktop/…etc

Perfidiouswulff
Автор

Life saver 🎉🎉🎉 working on a installation was the last part i needed

SuperBlackfox
Автор

The command is working properly so simple and straightforward .

farazahmed
Автор

terminal works but doesnt run on start up

ywx
Автор

thank you! so many other people were saying to do this in the most convoluted way possible.

trliiv
Автор

Hi! How do I do this if my python script is on a virtual environment?

tukmolitus
Автор

This is good, its an easy way of doing it.! however, making daemons is the way to go when you need to ensure a program that crashes can re-open automatically.

ScorgeRudess
Автор

what if i need to turn on a virtual environment before running the script? do i add the 'source env/bin/activate' command in the cron file?

erdhyernando
Автор

IDK what happen, my project is running but not reproduce the mp3 in this way. Can you help me, please?

antitialaman
Автор

Absolute life saver, why it no other tutorial this simple??

Missin
Автор

what if you want to run multiple bash scripts one after the other because I have to run startx followed by two bash scripts
'

time.py-neum
Автор

How about when we don't want the code to run at startup in the future? Do we just delete the crontab command?

muhammadallif
Автор

with this, does the pi also not need to be able to log in automatically with the username and password? How can it run the code without logging in first?

xyliusdominicibayan
Автор

In my case I created a server with python, and my sever uses a CSV file for checking some data. Now how I can set the working directory of my server so that any data file my server needed can easily executed !

Akct
Автор

Hey is it possible to call to run multiple files at the same time on startup and/or would it be as simple as another line imitating what is shown for the second python file to run?

reedjohnson
Автор

How can I change the editor again, I chose wrong when I asked myself. pleasee

fernandoalbornoz
Автор

My code needs to use the values ​​from the pickle file so cd myfolder must be used before it can run. Is there a way to write a script run? Please.

romtham
Автор

if I type:
"python3 main.py" it runs
But if I type the entire path:
"python3 /home/pi/main.py" it won't run.. and I get:
"can't open file: [Errno 2] No such file or directory"

Anyone had my same problem?
How can I fix this?
Thanks

tommicava
Автор

Hey thanks what if I want to run two scripts for example a python and a pure data one? I tried putting both in @reboot on crontab but it did not work for the second.

thejestern
Автор

i have a question if you need to update your bash file, how can you do that ? i have to make changes to it but when i update the image is keeping the original file i set to for automation..

rorionstar