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

Поділитися
Вставка
  • Опубліковано 27 лис 2024

КОМЕНТАРІ • 137

  • @Perfidiouswulff
    @Perfidiouswulff Рік тому +34

    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

    • @mingjianli8718
      @mingjianli8718 Рік тому +2

      Tried sleep60, sleep 60...Still not work. Don't know why

    • @DynamicSeq
      @DynamicSeq Рік тому

      @@mingjianli8718 I have same problem..

    • @mllhild
      @mllhild 7 місяців тому

      Tried it, but still isnt working

    • @mycomputerthings
      @mycomputerthings 6 місяців тому

      does not work

    • @ChandanKumar-zw7zg
      @ChandanKumar-zw7zg 6 місяців тому +3

      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 .

  • @trliiv1842
    @trliiv1842 2 роки тому +13

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

  • @kylerwade7072
    @kylerwade7072 10 місяців тому +2

    I LOVE YOU JUST FIXED A PROBLEM I HAVE BEEN HAVING FOR 2 YEARS

  • @Missi0n141
    @Missi0n141 Рік тому +11

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

  • @SuperBlackfox22
    @SuperBlackfox22 2 роки тому +10

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

  • @ddabble
    @ddabble 6 місяців тому +1

    thank you for keeping it straight to the point and not having a 20 step program :D

  • @processing6546
    @processing6546 5 місяців тому +2

    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.

  • @tukmolitus16
    @tukmolitus16 7 місяців тому +5

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

    • @rafinursandi5828
      @rafinursandi5828 5 місяців тому

      hey did you got an update about that i had the same problem thanks

    • @DigitalDuck-r4c
      @DigitalDuck-r4c 3 місяці тому

      @@rafinursandi5828 Any updates?

    • @ThatMusicBlog
      @ThatMusicBlog 2 місяці тому +3

      I had same issue. You have to put some prefix before the python script. For me my VE was named venv1 so my script looked like this:
      venv1/bin/python3 /home/pi/Documents/player.py
      Hope that helps

    • @UndercoverNoises
      @UndercoverNoises Місяць тому

      @@ThatMusicBlogomg. After a month of searching for this answer i find it in a youtube comment. Thank you so much

  • @farazahmed4976
    @farazahmed4976 Рік тому +2

    The command is working properly so simple and straightforward .

  • @ywx99
    @ywx99 Рік тому +21

    terminal works but doesnt run on start up

  • @kkkardoso10
    @kkkardoso10 28 днів тому

    That's awesome. Thank you! And how do I make it return to the normal boot?

  • @kevinmccann8652
    @kevinmccann8652 8 місяців тому

    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.

  • @StudentTrader
    @StudentTrader Рік тому +1

    Awesome! Now how do I get it to not run on start up?

  • @SuperMicroguy
    @SuperMicroguy Місяць тому

    OK, now my RPI-Pico immediately starts a game. When someone wants to get out of the game and go back to, say, the Thonny window, how do they do that? Include a pushbutton-checking routine that quits the game loop? Use a keyboard input to end the game? I want the gane to run again and again unless I do something to exit it. Thanks. Very good tutorial.

  • @abhivihi7741
    @abhivihi7741 7 місяців тому +1

    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!

  • @erdhyernando
    @erdhyernando 3 місяці тому +2

    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?

    • @07.ilhanhashimbinmohdnorfa75
      @07.ilhanhashimbinmohdnorfa75 6 днів тому

      Hi , my case is similar to yours, any updates?

    • @erdhyernando
      @erdhyernando 6 днів тому

      @@07.ilhanhashimbinmohdnorfa75 for my projects we end up not using virtual environment and for automatically running the scripts we use bashrc

  • @pain8117
    @pain8117 Рік тому +1

    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?

    • @lemonjuce13
      @lemonjuce13 Рік тому +1

      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.

  • @leonardofigueiredo2483
    @leonardofigueiredo2483 Рік тому +1

    Hi... to stop and back to normal, is it just use a ssh and edit this line on crontab?

  • @oguzcan815
    @oguzcan815 11 місяців тому

    you saved me hard man. THANK. YOU take care

  • @izzy1335
    @izzy1335 Рік тому +1

    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?

    • @letslearnsomethingnew9685
      @letslearnsomethingnew9685 10 місяців тому

      Did you solved the issue?
      If yes please guide, facing the same problem
      Do I need to use ,
      While True:
      ?

  • @antitialaman7301
    @antitialaman7301 Рік тому +1

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

  • @ScorgeRudess
    @ScorgeRudess 3 місяці тому

    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.

  • @hcracer1985
    @hcracer1985 10 місяців тому

    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.

  • @hutfris1532
    @hutfris1532 Рік тому +1

    Hello, how do you stop the program after running it?

    • @benjaminbrnic2958
      @benjaminbrnic2958 Рік тому

      Try using the command sudo crontab -r (I'd recommend checking your list of crontab commands first by using sudo crontab -l)

  • @Akct123
    @Akct123 10 місяців тому

    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 !

  • @BodyPress91
    @BodyPress91 7 місяців тому

    danke. das wollte ich so schnell wie möglich nochmal wissen.

  • @discipleoftheword1785
    @discipleoftheword1785 9 місяців тому

    Thank you! Perfect!

  • @johnconnor6735
    @johnconnor6735 8 місяців тому

    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?

  • @mytrade5413
    @mytrade5413 Рік тому

    thank you so much for your input, it's great

  • @reedjohnson6576
    @reedjohnson6576 7 місяців тому

    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?

  • @muhammadallif1212
    @muhammadallif1212 7 місяців тому

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

  • @joshiharsh5846
    @joshiharsh5846 Рік тому

    hi can i run grc files in above mentioned method? please reply...

  • @time.py88-ne8um
    @time.py88-ne8um 3 місяці тому

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

  • @CATZ129
    @CATZ129 Рік тому

    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?

  • @romtham2505
    @romtham2505 Рік тому

    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.

  • @RollingInBoost
    @RollingInBoost Рік тому

    thanks Sam!

  • @jaydenskelly8897
    @jaydenskelly8897 Місяць тому

    Wait wait wait... I only you know as a bike celebrity!

  • @thejestern
    @thejestern Рік тому

    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.

    • @SamWestbyTech
      @SamWestbyTech  Рік тому +3

      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

  • @akshatprakash9596
    @akshatprakash9596 8 місяців тому +1

    Does anyone know how I can make my pi wait until it is connected to the internet before running the script?

  • @hossamsamir1141
    @hossamsamir1141 2 роки тому +1

    Your content is very helpful , thank you .

  • @yuvalthecookie4132
    @yuvalthecookie4132 Рік тому

    thx you so much, works perfectly

  • @rorionstar
    @rorionstar Рік тому

    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..

  • @fernandoalbornoz3383
    @fernandoalbornoz3383 4 місяці тому

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

  • @pochirambo
    @pochirambo Рік тому

    Quick and easy. Gratz

  • @chotu.tech-yt
    @chotu.tech-yt 2 роки тому

    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

  • @TheDestinationSound
    @TheDestinationSound Рік тому

    Can I just add the bash command directly in the crontab file?

  • @T31J
    @T31J Рік тому

    well made and helpful

  • @Bennemann22
    @Bennemann22 Місяць тому

    I need that every time the Raspberry Pi starts, it opens a photo in a specific folder and puts the photo in slideshow mode. How can I do this?

  • @yisuslalala
    @yisuslalala Рік тому

    You're the best!

  • @lahirusandaruwan7977
    @lahirusandaruwan7977 Рік тому

    Is this working on Jetson nano?

  • @blacksurimi3851
    @blacksurimi3851 2 роки тому

    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.

    • @SamWestbyTech
      @SamWestbyTech  2 роки тому +1

      What you type in your terminal is what you use. If you type python3 when you normally run the script, then include python3

    • @blacksurimi3851
      @blacksurimi3851 2 роки тому

      @@SamWestbyTech Thank you.

  • @0xN1nja
    @0xN1nja Рік тому

    it workeddd thanks!

  • @gamermd9976
    @gamermd9976 11 місяців тому

    but if my script uses or calls other files/folders?

  • @alphachannellabs3947
    @alphachannellabs3947 7 місяців тому

    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.

    • @edht2
      @edht2 3 місяці тому

      I'm having the same issue, I just found out it does not run commands with root :(

  • @romtham2505
    @romtham2505 Рік тому

    Thank you.

  • @kevincranfield2471
    @kevincranfield2471 7 місяців тому

    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

  • @ezzeldin101
    @ezzeldin101 Рік тому

    Short
    Easy
    Helpful

  • @hotchannel2070
    @hotchannel2070 2 роки тому

    Hi mate, I have a face detection code on Raspberry Pi, and it works on pycharm. How can I work it like that?

    • @omarbouguerne1467
      @omarbouguerne1467 Рік тому

      Hey can u give your code i really need it if u can share it with me

  • @harikrishnasamy1551
    @harikrishnasamy1551 2 роки тому

    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?

    • @SamWestbyTech
      @SamWestbyTech  2 роки тому

      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

    • @harikrishnasamy1551
      @harikrishnasamy1551 2 роки тому

      @@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...

  • @EieiExamplEeiEi
    @EieiExamplEeiEi 9 місяців тому

    Cool luv it

  • @explorejambi
    @explorejambi Рік тому

    how about screensaver video bro?

  • @metehancakr6943
    @metehancakr6943 2 роки тому

    Thx it helped me

  • @cobalt01snet
    @cobalt01snet 9 місяців тому

    I need to run a command prompt .sh at startup and leave it open, I tried this and no sign of the command prompt

  • @RenRuin
    @RenRuin Рік тому

    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.

    • @tamilmynthan860
      @tamilmynthan860 11 місяців тому

      Make sure the required files(example: mp3 files) are in the same folder as your code

  • @КамилаКуатова-н4к
    @КамилаКуатова-н4к Місяць тому

    How to print log file ?

  • @whitehathacker5314
    @whitehathacker5314 2 роки тому

    can you make a video on that

  • @prabingautam421
    @prabingautam421 2 роки тому

    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?

    • @theredneckscientist2000
      @theredneckscientist2000 11 місяців тому

      After setting up the pi, you shouldn’t need to log in again ever. Unless you log out before shutting down

  • @tommicava9675
    @tommicava9675 2 роки тому +1

    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

    • @SamWestbyTech
      @SamWestbyTech  2 роки тому +1

      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

  • @rajdeep1229
    @rajdeep1229 Рік тому

    It's not working in my case. Can you please help me

  • @JM-bd4mg
    @JM-bd4mg 2 роки тому

    Hi, can i ask how to run a script on startup in a virtual environment?

    • @SamWestbyTech
      @SamWestbyTech  2 роки тому

      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

  • @paulopaim3944
    @paulopaim3944 2 роки тому

    Tks you so much

  • @nov12th64
    @nov12th64 Рік тому

    life saverr

  • @user-ig6hg6jd1y
    @user-ig6hg6jd1y 2 роки тому +1

    After this how can we return to the desktop

  • @mike-oh7pz
    @mike-oh7pz Рік тому

    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

  • @bobyau8755
    @bobyau8755 Рік тому

    Hi, I have watched and followed the instruction shown in the video. However, it did notwork. I don't know what the problem is.

    • @SamWestbyTech
      @SamWestbyTech  Рік тому

      When you run the commands in your terminal do they work? That's how you can troubleshoot before trying them in crontab

    • @bobyau8755
      @bobyau8755 Рік тому

      @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

    • @tusharalase7472
      @tusharalase7472 Рік тому

      @@bobyau8755 Hi Bob, I am getting the same error, could you solve it ?

    • @bobyau8755
      @bobyau8755 Рік тому

      @@tusharalase7472 not yet, I'm in uni, need to be back at home to play with my robot

  • @ramyabettaswamy2651
    @ramyabettaswamy2651 2 роки тому

    hi i want How to Run a scratch3 Script on Startup for Raspberry Pi 4

  • @whitehathacker5314
    @whitehathacker5314 2 роки тому

    sir can we auto run the file which contain text and python script

  • @Putridi.
    @Putridi. Рік тому

    cant get it to work im afraid.. followed exact

  • @TheStevoth
    @TheStevoth 10 місяців тому

    Cowabunga dude!

  • @meliocurie1809
    @meliocurie1809 Рік тому

    How do you run multiple scripts?

  • @Nomis180
    @Nomis180 6 місяців тому

    👏👏

  • @mllhild
    @mllhild 7 місяців тому

    sadly is only working in the terminal, but not on reboot

  • @beepboop-o5s
    @beepboop-o5s Рік тому

    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

  • @Andrei-t8j
    @Andrei-t8j Рік тому

    great job friend, but i want to notice noobs like me that for me worked only without 'sudo'

  • @samarreola2123
    @samarreola2123 2 роки тому

    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
      @SamWestbyTech  2 роки тому +1

      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

    • @samarreola2123
      @samarreola2123 2 роки тому

      @@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.

  • @sujaychintu589
    @sujaychintu589 2 місяці тому

    for me its not working

  • @cheems6559
    @cheems6559 Рік тому

    Not working for me

  • @StitchesLovesRats
    @StitchesLovesRats 9 місяців тому

    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.

  • @theskoob2944
    @theskoob2944 7 місяців тому +1

    Didn't work

  • @OffroadMXbohemia
    @OffroadMXbohemia 6 місяців тому

    dont work at all

    • @Coolpackers
      @Coolpackers 5 місяців тому

      What did you put in the crontab? And wdym it doesn't work?

  • @AlphastarStudios
    @AlphastarStudios 10 місяців тому

    Didn’t work for me

  • @whitekanyewestthebully1346
    @whitekanyewestthebully1346 Рік тому

    dont know why but this didnt work for me

  • @aerr4512
    @aerr4512 18 днів тому

    this killed my pi. how to stop it from running? I was playing a video in full screen and now is impossible to access the terminal.

  • @siddhantbhusari
    @siddhantbhusari Рік тому

    Thanks Man Appericiate the content

  • @kheilanthonycunanan9855
    @kheilanthonycunanan9855 20 днів тому

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

  • @xyliusdominicibayan6215
    @xyliusdominicibayan6215 2 роки тому +2

    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?

    • @paarthmittal4557
      @paarthmittal4557 2 роки тому +1

      U can enable auto login in raspberrypi configuration

  • @ais_robotic
    @ais_robotic 7 місяців тому

    Thank u so much

  • @SickAsFooM
    @SickAsFooM Рік тому

    How do you disable it?