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
The solution is to run a terminal with the command to run code steps :- . Make sure script is executible chmod +x /home/pi/your program.py .Open crontab. -e crontab -e . Entre command @reboot lxterminal -e /usr/bin/python3 /home/pi/your_program.py And use (&) in if code is not running with above command thank U .
Those who are wondering how to undo this : Open crontab: crontab -e (or sudo crontab -e if you used sudo initially) Find the entry: Look for the line you added earlier, which starts with @reboot. Delete the entry: Remove the entire line by pressing dd (or use the delete key). Save and exit: Save the changes and exit the editor.
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.
for those where crontab didnt do anything, in nano editor, try pressing ctrl+T and then execute the python code and if you have any error, once the code runs without any error in nano editor, delete the generated lines and sudo shutdown -h now, switchoff and then on Peace Out!
Excellent! Short and to the point. I did "crontab -e" without the sudo, because the system seems to boot into my user name. Not sure about this. Thanks again.
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?
I activated the code and it worked, my servo would spin but the whole program only ran for a few seconds before stopping, how do i make it run continuosly until the power is cut?
If you are running the script with root priveleges you dont, but if you dont those commands will just not go through because the permission gets denied.
Hey. How do I get it to boot up where I left off at? I’m using it to monitor my vehicles gauges and have made adjustments but when I power down ot doesn’t start where I left off and have to make those adjustments again.
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 !
I have a python script that involves neopixels. I have to go to terminal and type sudo thorny to open thorny and write the script. The script is saved in the root disk or memory. How can I get a program like that to start from start up?
hey is there a way for the Pi to run a sudo command upon boot? I'm running VirtualHere USB over IP and i want my Pi to run a Terminal sudo command every time it boots.
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..
can i burn this script along with os image file to execute script post installation? My objective is to install few software and configure few settings in raspberry pi post os installation
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?
when I try to run the python code in one line I get an error saying it can't see the the other file names in the folder like tiffs even tho they are in the folder if I use this line python3 DEV/poster/poster49.py it errors but in terminal if I cd DEV/poster then run python3 poster49.py it runs fine. Don't understand why I can't run in one line
Hi thank you for the video, I want to run an executable, in this case its Universal Gcode Sender (an application for CNC machines) but it wont boot on start up, there was no error messages displayed, do you know what could be the problem?
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
Open your terminal and try typing "ls /home". This lists the files in the "home" directory. Do you see "pi" in the output? Next type "ls /home/pi". What files do you see? Do you see "main.py"? If not, then main.py is in a different place
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.
You have to separate the commands with semi-colons. If that doesn't work then there's something wrong with your other command. Try running the command in your terminal and see if it works before trying it in crontab
You should have made the video a little more complex like adding two or more scripts to run at startup. Because that's what im trying to figure out how to do right nw
@@SamWestbyTech thank you sam.....now i have completed running a basic program when booting up ( like a led blink, etc.). my main program is running successfully in the python terminal but when writing it in crontab it's not working how to diagnose the problem...
bro. trying to get a wifi tool to run on startup on pi zero with re4son kernel for a week. followed every long ass convoluted tutorial seven times and youtube hid this video until i was digging so deep most of the results werent even relevant. algorithm sucks
Yes this is possible. I believe you just have to edit the crontab file to be the command to activate your virtual environment, then a semicolon “;”, then the command to run your script
I've never had a tutorial from a gfloating head before. Are you preparing for a Futurama future? 😅 Sorry, jk, but the vid would look better with a wider shot.
Hello, great and easy advice. Question. How do you go back to normal mode? What if you want to go back to R-pi to modify script or go back to the use of monitor and keyboard?
@@SamWestbyTech This video is awesome. Helped me a lot to get my application working easy. I m new R pi user and I did not know if after this set up as shown on your video I could have my keyboard and mouse connected or not to my r-pi. Many thanks again my application works as desired.
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?
Does this not work for pygame? I keep getting errors saying that directories included in the code don't exist when I try to run it from the terminal. If I run it from and IDE it works fine. Any suggestions would be much appreciated. I'm a total noob.
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
Tried sleep60, sleep 60...Still not work. Don't know why
@@mingjianli8718 I have same problem..
Tried it, but still isnt working
does not work
The solution is to run a terminal with the command to run code steps :-
. Make sure script is executible
chmod +x /home/pi/your program.py
.Open crontab. -e
crontab -e
. Entre command
@reboot lxterminal -e /usr/bin/python3 /home/pi/your_program.py
And use (&) in if code is not running with above command thank U .
thank you! so many other people were saying to do this in the most convoluted way possible.
Absolute life saver, why it no other tutorial this simple??
thank you for keeping it straight to the point and not having a 20 step program :D
I LOVE YOU JUST FIXED A PROBLEM I HAVE BEEN HAVING FOR 2 YEARS
Life saver 🎉🎉🎉 working on a installation was the last part i needed
The command is working properly so simple and straightforward .
terminal works but doesnt run on start up
Those who are wondering how to undo this :
Open crontab: crontab -e (or sudo crontab -e if you used sudo initially)
Find the entry: Look for the line you added earlier, which starts with @reboot.
Delete the entry: Remove the entire line by pressing dd (or use the delete key).
Save and exit: Save the changes and exit the editor.
Hi! How do I do this if my python script is on a virtual environment?
hey did you got an update about that i had the same problem thanks
@@rafinursandi5828 Any updates?
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.
you saved me hard man. THANK. YOU take care
for those where crontab didnt do anything, in nano editor, try pressing ctrl+T and then execute the python code and if you have any error, once the code runs without any error in nano editor, delete the generated lines and sudo shutdown -h now, switchoff and then on
Peace Out!
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?
danke. das wollte ich so schnell wie möglich nochmal wissen.
Excellent! Short and to the point. I did "crontab -e" without the sudo, because the system seems to boot into my user name. Not sure about this.
Thanks again.
Thank you! Perfect!
thank you so much for your input, it's great
thanks Sam!
Quick and easy. Gratz
thx you so much, works perfectly
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?
U can enable auto login in raspberrypi configuration
well made and helpful
it workeddd thanks!
You're the best!
I activated the code and it worked, my servo would spin but the whole program only ran for a few seconds before stopping, how do i make it run continuosly until the power is cut?
Did you solved the issue?
If yes please guide, facing the same problem
Do I need to use ,
While True:
?
Your content is very helpful , thank you .
Thank you.
Short
Easy
Helpful
Thank u so much
Hi... to stop and back to normal, is it just use a ssh and edit this line on crontab?
Thx it helped me
IDK what happen, my project is running but not reproduce the mp3 in this way. Can you help me, please?
Cool luv it
Thank you so much for this tutorial, but I had one question
Do I need to do anything differently if I am running a script that needs SUDO privileges?
If you are running the script with root priveleges you dont, but if you dont those commands will just not go through because the permission gets denied.
Tks you so much
life saverr
Hey. How do I get it to boot up where I left off at? I’m using it to monitor my vehicles gauges and have made adjustments but when I power down ot doesn’t start where I left off and have to make those adjustments again.
what if you want to run multiple bash scripts one after the other because I have to run startx followed by two bash scripts
'
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 !
I have a python script that involves neopixels. I have to go to terminal and type sudo thorny to open thorny and write the script. The script is saved in the root disk or memory. How can I get a program like that to start from start up?
How about when we don't want the code to run at startup in the future? Do we just delete the crontab command?
Awesome! Now how do I get it to not run on start up?
How can I change the editor again, I chose wrong when I asked myself. pleasee
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.
hey is there a way for the Pi to run a sudo command upon boot?
I'm running VirtualHere USB over IP and i want my Pi to run a Terminal sudo command every time it boots.
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..
can i burn this script along with os image file to execute script post installation? My objective is to install few software and configure few settings in raspberry pi post os installation
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?
when I try to run the python code in one line I get an error saying it can't see the the other file names in the folder like tiffs even tho they are in the folder if I use this line python3 DEV/poster/poster49.py it errors but in terminal if I cd DEV/poster then run python3 poster49.py it runs fine. Don't understand why I can't run in one line
hi can i run grc files in above mentioned method? please reply...
Can I just add the bash command directly in the crontab file?
Hi thank you for the video, I want to run an executable, in this case its Universal Gcode Sender (an application for CNC machines) but it wont boot on start up, there was no error messages displayed, do you know what could be the problem?
i have the same issue
sadly is only working in the terminal, but not on reboot
but if my script uses or calls other files/folders?
I need to run a command prompt .sh at startup and leave it open, I tried this and no sign of the command prompt
Thanks Man Appericiate the content
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
Open your terminal and try typing "ls /home". This lists the files in the "home" directory. Do you see "pi" in the output? Next type "ls /home/pi". What files do you see? Do you see "main.py"? If not, then main.py is in a different place
Cowabunga dude!
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.
You have to separate the commands with semi-colons. If that doesn't work then there's something wrong with your other command. Try running the command in your terminal and see if it works before trying it in crontab
It's not working in my case. Can you please help me
Didn't work
Does anyone know how I can make my pi wait until it is connected to the internet before running the script?
👏👏
can you make a video on that
cant get it to work im afraid.. followed exact
You should have made the video a little more complex like adding two or more scripts to run at startup. Because that's what im trying to figure out how to do right nw
After this how can we return to the desktop
Same question.
use putty
Hi mate, I have a face detection code on Raspberry Pi, and it works on pycharm. How can I work it like that?
Hey can u give your code i really need it if u can share it with me
super...I have one doubt.....if i want to run a python file in diffierent environment (not from the base environment ex: PyTorch) how to do that?
I believe you just need to add the command to activate your environment, then a semi-colon, then the command to run your Python file
@@SamWestbyTech thank you sam.....now i have completed running a basic program when booting up ( like a led blink, etc.). my main program is running successfully in the python terminal but when writing it in crontab it's not working how to diagnose the problem...
Is this working on Jetson nano?
How do you disable it?
Hello, how do you stop the program after running it?
Try using the command sudo crontab -r (I'd recommend checking your list of crontab commands first by using sudo crontab -l)
how about screensaver video bro?
great job friend, but i want to notice noobs like me that for me worked only without 'sudo'
hi i want How to Run a scratch3 Script on Startup for Raspberry Pi 4
Hi, I have watched and followed the instruction shown in the video. However, it did notwork. I don't know what the problem is.
When you run the commands in your terminal do they work? That's how you can troubleshoot before trying them in crontab
@Sam Westby Tech the terminal did the exact thing as shown on the video. However, it just don't run the code as expected to when I restart the pi
@@bobyau8755 Hi Bob, I am getting the same error, could you solve it ?
@@tusharalase7472 not yet, I'm in uni, need to be back at home to play with my robot
bro. trying to get a wifi tool to run on startup on pi zero with re4son kernel for a week. followed every long ass convoluted tutorial seven times and youtube hid this video until i was digging so deep most of the results werent even relevant. algorithm sucks
Hi, can i ask how to run a script on startup in a virtual environment?
Yes this is possible. I believe you just have to edit the crontab file to be the command to activate your virtual environment, then a semicolon “;”, then the command to run your script
Not working for me
sir can we auto run the file which contain text and python script
yes you can!
How do you run multiple scripts?
Separate them with a semi-colon
I've never had a tutorial from a gfloating head before. Are you preparing for a Futurama future? 😅
Sorry, jk, but the vid would look better with a wider shot.
Didn’t work for me
dont know why but this didnt work for me
Hello, great and easy advice. Question. How do you go back to normal mode? What if you want to go back to R-pi to modify script or go back to the use of monitor and keyboard?
Thanks, Sam. What do you mean by normal mode? If you mean how to exit the Nano text editor, you can press CTRL+S to save then CTRL+X to exit
@@SamWestbyTech This video is awesome. Helped me a lot to get my application working easy. I m new R pi user and I did not know if after this set up as shown on your video I could have my keyboard and mouse connected or not to my r-pi. Many thanks again my application works as desired.
dont work at all
What did you put in the crontab? And wdym it doesn't work?
That’s helpful. I have a script for my Sense hat. Do I have to type python3 in as well?
Thank you so much. You saved my live.
What you type in your terminal is what you use. If you type python3 when you normally run the script, then include python3
@@SamWestbyTech Thank you.
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?
After setting up the pi, you shouldn’t need to log in again ever. Unless you log out before shutting down
Does this not work for pygame? I keep getting errors saying that directories included in the code don't exist when I try to run it from the terminal. If I run it from and IDE it works fine. Any suggestions would be much appreciated. I'm a total noob.
Make sure the required files(example: mp3 files) are in the same folder as your code