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

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ต.ค. 2024

ความคิดเห็น • 131

  • @trliiv1842
    @trliiv1842 2 ปีที่แล้ว +11

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

  • @Perfidiouswulff
    @Perfidiouswulff ปีที่แล้ว +33

    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 11 หลายเดือนก่อน

      @@mingjianli8718 I have same problem..

    • @mllhild
      @mllhild 6 หลายเดือนก่อน

      Tried it, but still isnt working

    • @mycomputerthings
      @mycomputerthings 5 หลายเดือนก่อน

      does not work

    • @ChandanKumar-zw7zg
      @ChandanKumar-zw7zg 5 หลายเดือนก่อน +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 .

  • @kylerwade7072
    @kylerwade7072 9 หลายเดือนก่อน +1

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

  • @Missi0n141
    @Missi0n141 11 หลายเดือนก่อน +10

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

  • @ddabble
    @ddabble 5 หลายเดือนก่อน +1

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

  • @farazahmed4976
    @farazahmed4976 ปีที่แล้ว +2

    The command is working properly so simple and straightforward .

  • @SuperBlackfox22
    @SuperBlackfox22 2 ปีที่แล้ว +10

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

  • @erdhyernando
    @erdhyernando 2 หลายเดือนก่อน +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?

  • @tukmolitus16
    @tukmolitus16 6 หลายเดือนก่อน +5

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

    • @rafinursandi5828
      @rafinursandi5828 4 หลายเดือนก่อน

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

    • @DigitalDuck-r4c
      @DigitalDuck-r4c 2 หลายเดือนก่อน

      @@rafinursandi5828 Any updates?

    • @ThatMusicBlog
      @ThatMusicBlog หลายเดือนก่อน +2

      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 18 วันที่ผ่านมา

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

  • @kevinmccann8652
    @kevinmccann8652 7 หลายเดือนก่อน

    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.

  • @oguzcan815
    @oguzcan815 10 หลายเดือนก่อน

    you saved me hard man. THANK. YOU take care

  • @processing6546
    @processing6546 4 หลายเดือนก่อน +1

    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.

  • @BodyPress91
    @BodyPress91 6 หลายเดือนก่อน

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

  • @mytrade5413
    @mytrade5413 11 หลายเดือนก่อน

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

  • @ywx99
    @ywx99 ปีที่แล้ว +19

    terminal works but doesnt run on start up

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

  • @discipleoftheword1785
    @discipleoftheword1785 8 หลายเดือนก่อน

    Thank you! Perfect!

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

  • @StudentTrader
    @StudentTrader ปีที่แล้ว

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

  • @reedjohnson6576
    @reedjohnson6576 6 หลายเดือนก่อน

    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?

  • @antitialaman7301
    @antitialaman7301 ปีที่แล้ว +1

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

  • @abhivihi7741
    @abhivihi7741 5 หลายเดือนก่อน +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!

  • @hcracer1985
    @hcracer1985 9 หลายเดือนก่อน

    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.

  • @yuvalthecookie4132
    @yuvalthecookie4132 ปีที่แล้ว

    thx you so much, works perfectly

  • @johnconnor6735
    @johnconnor6735 7 หลายเดือนก่อน

    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?

  • @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 9 หลายเดือนก่อน

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

  • @RollingInBoost
    @RollingInBoost ปีที่แล้ว

    thanks Sam!

  • @jaydenskelly8897
    @jaydenskelly8897 6 วันที่ผ่านมา

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

  • @pochirambo
    @pochirambo ปีที่แล้ว

    Quick and easy. Gratz

  • @yisuslalala
    @yisuslalala ปีที่แล้ว

    You're the best!

  • @time.py88-ne8um
    @time.py88-ne8um 2 หลายเดือนก่อน

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

  • @muhammadallif1212
    @muhammadallif1212 6 หลายเดือนก่อน

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

  • @Bennemann22
    @Bennemann22 24 วันที่ผ่านมา

    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?

  • @T31J
    @T31J ปีที่แล้ว

    well made and helpful

  • @hossamsamir1141
    @hossamsamir1141 2 ปีที่แล้ว +1

    Your content is very helpful , thank you .

  • @0xN1nja
    @0xN1nja ปีที่แล้ว

    it workeddd thanks!

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

  • @Akct123
    @Akct123 9 หลายเดือนก่อน

    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 !

  • @ScorgeRudess
    @ScorgeRudess 2 หลายเดือนก่อน

    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.

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

  • @kevincranfield2471
    @kevincranfield2471 6 หลายเดือนก่อน

    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

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

  • @joshiharsh5846
    @joshiharsh5846 ปีที่แล้ว

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

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

  • @akshatprakash9596
    @akshatprakash9596 7 หลายเดือนก่อน +1

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

  • @ezzeldin101
    @ezzeldin101 ปีที่แล้ว

    Short
    Easy
    Helpful

  • @fernandoalbornoz3383
    @fernandoalbornoz3383 3 หลายเดือนก่อน

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

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

  • @alphachannellabs3947
    @alphachannellabs3947 6 หลายเดือนก่อน

    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 หลายเดือนก่อน

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

  • @EieiExamplEeiEi
    @EieiExamplEeiEi 8 หลายเดือนก่อน

    Cool luv it

  • @romtham2505
    @romtham2505 ปีที่แล้ว

    Thank you.

  • @TheDestinationSound
    @TheDestinationSound ปีที่แล้ว

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

  • @gamermd9976
    @gamermd9976 10 หลายเดือนก่อน

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

  • @cobalt01snet
    @cobalt01snet 8 หลายเดือนก่อน

    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 10 หลายเดือนก่อน

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

  • @siddhantbhusari
    @siddhantbhusari ปีที่แล้ว

    Thanks Man Appericiate the content

  • @lahirusandaruwan7977
    @lahirusandaruwan7977 ปีที่แล้ว

    Is this working on Jetson nano?

  • @metehancakr6943
    @metehancakr6943 2 ปีที่แล้ว

    Thx it helped 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...

  • @ais_robotic
    @ais_robotic 6 หลายเดือนก่อน

    Thank u so much

  • @hutfris1532
    @hutfris1532 11 หลายเดือนก่อน

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

    • @benjaminbrnic2958
      @benjaminbrnic2958 11 หลายเดือนก่อน

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

  • @КамилаКуатова-н4к
    @КамилаКуатова-н4к 2 วันที่ผ่านมา

    How to print log file ?

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

  • @nov12th64
    @nov12th64 ปีที่แล้ว

    life saverr

  • @TheStevoth
    @TheStevoth 9 หลายเดือนก่อน

    Cowabunga dude!

  • @rajdeep1229
    @rajdeep1229 ปีที่แล้ว

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

  • @Nomis180
    @Nomis180 5 หลายเดือนก่อน

    👏👏

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

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

  • @explorejambi
    @explorejambi 11 หลายเดือนก่อน

    how about screensaver video bro?

  • @user-ig6hg6jd1y
    @user-ig6hg6jd1y 2 ปีที่แล้ว +1

    After this how can we return to the desktop

  • @whitehathacker5314
    @whitehathacker5314 2 ปีที่แล้ว

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

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

  • @Putridi.
    @Putridi. ปีที่แล้ว

    cant get it to work im afraid.. followed exact

  • @whitehathacker5314
    @whitehathacker5314 2 ปีที่แล้ว

    can you make a video on that

  • @meliocurie1809
    @meliocurie1809 ปีที่แล้ว

    How do you run multiple scripts?

    • @SamWestbyTech
      @SamWestbyTech  ปีที่แล้ว

      Separate them with a semi-colon

  • @mllhild
    @mllhild 6 หลายเดือนก่อน

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

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

  • @ramyabettaswamy2651
    @ramyabettaswamy2651 2 ปีที่แล้ว

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

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

  • @sujaychintu589
    @sujaychintu589 หลายเดือนก่อน

    for me its not working

  • @Andrei-t8j
    @Andrei-t8j ปีที่แล้ว

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

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

  • @cheems6559
    @cheems6559 ปีที่แล้ว

    Not working for me

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

  • @StitchesLovesRats
    @StitchesLovesRats 8 หลายเดือนก่อน

    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 6 หลายเดือนก่อน +1

    Didn't work

  • @AlphastarStudios
    @AlphastarStudios 9 หลายเดือนก่อน

    Didn’t work for me

  • @whitekanyewestthebully1346
    @whitekanyewestthebully1346 ปีที่แล้ว

    dont know why but this didnt work for me

  • @OffroadMXbohemia
    @OffroadMXbohemia 5 หลายเดือนก่อน

    dont work at all

    • @Coolpackers
      @Coolpackers 4 หลายเดือนก่อน

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

  • @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 10 หลายเดือนก่อน

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

  • @paulopaim3944
    @paulopaim3944 2 ปีที่แล้ว

    Tks you so much

  • @SickAsFooM
    @SickAsFooM ปีที่แล้ว

    How do you disable it?