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

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024

Комментарии • 123

  • @Perfidiouswulff
    @Perfidiouswulff Год назад +28

    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 9 месяцев назад +2

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

    • @DynamicSeq
      @DynamicSeq 9 месяцев назад

      @@mingjianli8718 I have same problem..

    • @mllhild
      @mllhild 4 месяца назад

      Tried it, but still isnt working

    • @mycomputerthings
      @mycomputerthings 3 месяца назад

      does not work

    • @ChandanKumar-zw7zg
      @ChandanKumar-zw7zg 3 месяца назад +2

      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 Год назад +11

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

  • @Missi0n141
    @Missi0n141 8 месяцев назад +8

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

  • @ddabble
    @ddabble 3 месяца назад +1

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

  • @kylerwade7072
    @kylerwade7072 6 месяцев назад +1

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

  • @SuperBlackfox22
    @SuperBlackfox22 Год назад +10

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

  • @farazahmed4976
    @farazahmed4976 Год назад +2

    The command is working properly so simple and straightforward .

  • @ywx99
    @ywx99 Год назад +15

    terminal works but doesnt run on start up

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

  • @johnjosephvalderama7130
    @johnjosephvalderama7130 4 месяца назад +4

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

    • @rafinursandi5828
      @rafinursandi5828 2 месяца назад

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

    • @user-uq1qq7pj8h
      @user-uq1qq7pj8h 2 дня назад

      @@rafinursandi5828 Any updates?

  • @ScorgeRudess
    @ScorgeRudess 8 дней назад

    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.

  • @oguzcan815
    @oguzcan815 8 месяцев назад

    you saved me hard man. THANK. YOU take care

  • @abhivihi7741
    @abhivihi7741 3 месяца назад

    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 16 дней назад +1

    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?

  • @BodyPress91
    @BodyPress91 4 месяца назад

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

  • @kevinmccann8652
    @kevinmccann8652 5 месяцев назад

    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.

  • @discipleoftheword1785
    @discipleoftheword1785 6 месяцев назад

    Thank you! Perfect!

  • @mytrade5413
    @mytrade5413 9 месяцев назад

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

  • @RollingInBoost
    @RollingInBoost 11 месяцев назад

    thanks Sam!

  • @pochirambo
    @pochirambo Год назад

    Quick and easy. Gratz

  • @yuvalthecookie4132
    @yuvalthecookie4132 Год назад

    thx you so much, works perfectly

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

  • @T31J
    @T31J Год назад

    well made and helpful

  • @0xN1nja
    @0xN1nja Год назад

    it workeddd thanks!

  • @yisuslalala
    @yisuslalala Год назад

    You're the best!

  • @izzy1335
    @izzy1335 10 месяцев назад +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 7 месяцев назад

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

  • @hossamsamir1141
    @hossamsamir1141 2 года назад +1

    Your content is very helpful , thank you .

  • @romtham2505
    @romtham2505 Год назад

    Thank you.

  • @ezzeldin101
    @ezzeldin101 Год назад

    Short
    Easy
    Helpful

  • @Ais-qc1bc
    @Ais-qc1bc 4 месяца назад

    Thank u so much

  • @leonardofigueiredo2483
    @leonardofigueiredo2483 Год назад +1

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

  • @metehancakr6943
    @metehancakr6943 2 года назад

    Thx it helped me

  • @antitialaman7301
    @antitialaman7301 Год назад +1

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

  • @EieiExamplEeiEi
    @EieiExamplEeiEi 5 месяцев назад

    Cool luv it

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

  • @paulopaim3944
    @paulopaim3944 2 года назад

    Tks you so much

  • @nov12th64
    @nov12th64 Год назад

    life saverr

  • @hcracer1985
    @hcracer1985 7 месяцев назад

    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.

  • @time.py88-ne8um
    @time.py88-ne8um 12 дней назад

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

  • @Akct123
    @Akct123 7 месяцев назад

    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 !

  • @johnconnor6735
    @johnconnor6735 5 месяцев назад

    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?

  • @muhammadallif1212
    @muhammadallif1212 4 месяца назад

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

  • @StudentTrader
    @StudentTrader 10 месяцев назад

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

  • @fernandoalbornoz3383
    @fernandoalbornoz3383 Месяц назад

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

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

  • @alphachannellabs3947
    @alphachannellabs3947 4 месяца назад

    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.

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

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

  • @reedjohnson6576
    @reedjohnson6576 4 месяца назад

    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?

  • @kevincranfield2471
    @kevincranfield2471 3 месяца назад

    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

  • @joshiharsh5846
    @joshiharsh5846 Год назад

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

  • @TheDestinationSound
    @TheDestinationSound Год назад

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

  • @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?

  • @mllhild
    @mllhild 4 месяца назад

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

  • @gamermd9976
    @gamermd9976 7 месяцев назад

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

  • @cobalt01snet
    @cobalt01snet 6 месяцев назад

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

  • @siddhantbhusari
    @siddhantbhusari Год назад

    Thanks Man Appericiate the content

  • @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  Год назад +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

  • @TheStevoth
    @TheStevoth 7 месяцев назад

    Cowabunga dude!

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

  • @rajdeep1229
    @rajdeep1229 Год назад

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

  • @theskoob2944
    @theskoob2944 3 месяца назад +1

    Didn't work

  • @akshatprakash9596
    @akshatprakash9596 4 месяца назад

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

  • @Nomis180
    @Nomis180 3 месяца назад

    👏👏

  • @whitehathacker5314
    @whitehathacker5314 Год назад

    can you make a video on that

  • @Putridi.
    @Putridi. 10 месяцев назад

    cant get it to work im afraid.. followed exact

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

  • @user-ig6hg6jd1y
    @user-ig6hg6jd1y 2 года назад +1

    After this how can we return to the desktop

  • @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?

    • @omarbouguerne8508
      @omarbouguerne8508 Год назад

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

  • @harikrishnasamy1551
    @harikrishnasamy1551 Год назад

    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  Год назад

      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 Год назад

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

  • @lahirusandaruwan7977
    @lahirusandaruwan7977 11 месяцев назад

    Is this working on Jetson nano?

  • @SickAsFooM
    @SickAsFooM Год назад

    How do you disable it?

  • @hutfris1532
    @hutfris1532 9 месяцев назад

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

    • @benjaminbrnic2958
      @benjaminbrnic2958 9 месяцев назад

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

  • @explorejambi
    @explorejambi 9 месяцев назад

    how about screensaver video bro?

  • @user-yi9zy5rw6k
    @user-yi9zy5rw6k Год назад

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

  • @ramyabettaswamy2651
    @ramyabettaswamy2651 Год назад

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

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

  • @user-mc8xt1iq7c
    @user-mc8xt1iq7c Год назад

    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

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

  • @cheems6559
    @cheems6559 11 месяцев назад

    Not working for me

  • @whitehathacker5314
    @whitehathacker5314 Год назад

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

  • @meliocurie1809
    @meliocurie1809 Год назад

    How do you run multiple scripts?

  • @StitchesLovesRats
    @StitchesLovesRats 5 месяцев назад

    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.

  • @user-ty8qx6od9r
    @user-ty8qx6od9r 7 месяцев назад

    Didn’t work for me

  • @whitekanyewestthebully1346
    @whitekanyewestthebully1346 Год назад

    dont know why but this didnt work for me

  • @samarreola2123
    @samarreola2123 Год назад

    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  Год назад +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 Год назад

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

  • @OffroadMXbohemia
    @OffroadMXbohemia 2 месяца назад

    dont work at all

    • @Coolpackers
      @Coolpackers 2 месяца назад

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

  • @blacksurimi3851
    @blacksurimi3851 Год назад

    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  Год назад +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 Год назад

      @@SamWestbyTech Thank you.

  • @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 7 месяцев назад

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

  • @RenRuin
    @RenRuin 10 месяцев назад

    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 8 месяцев назад

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