0

So I'm using Raspbian to create a mobile GPS tracker. I wanted it to log data then safely shut down the pi when I was done. I figured I could just plug in my mini keyboard when I was done and click control-c to stop it. Well, everything worked according to plan, but I didn't have the forethought about when I'm done with my tests and need to use my pi again/get the data off of it. I chose to bypass the login and directly start running the script. So when I connected my pi to a display, I see it running the script as it's supposed to. The last line of the script says that on keyboard interrupt, run the shutdown -h now command through the os module. So, what I've done to myself is have it run a program that I can only get out of with keyboard interrupt and then when I use that automatically shut down the pi. So I can't stop this loop of running the script and shutting down to get back to normal operating conditions.

Any advice is appreciated.

The process I used to run on startup is from this webpage: http://www.raspberrypi-spy.co.uk/2015/02/how-to-autorun-a-python-script-on-raspberry-pi-boot/

  • I was able to get to a command line by changing the cmdline.txt to init=/bin/sh/ and I can get to my bad python file but it says its read-only file system even though I typed sudo. – regerd20 Sep 1 '15 at 20:24
  • 1
    Put cmdline.txt back to normal and boot the Pi. Press ctrl+alt+f1 to get a login window, login, edit your script, save, and reboot. – joan Sep 1 '15 at 20:35
  • I figured out how to fix it. On the cmdline.txt file i need to put rw before bootwait. That allows me to write. Then I can edit the broken python file. After fixing the python file to be totally commented out, I put cmdline.txt back to normal and use the comp like I would otherwise. – regerd20 Sep 1 '15 at 21:55
  • 1
    It's probably worthwhile to do a self answer so that the solution is clear to others. – joan Sep 1 '15 at 22:02
1

I fixed it by first stopping my script from running.

I held shift and went into the noobs setup. From there you can edit cmdline.txt

In cmdline.txt I put rw in front of rootwait and added init=/bin/sh/

Then I restarted the Pi. This brought me to the command line at start instead of my python script running.

I typed sudo nano /home/pi/myfilename.py

I then edited the python file so the entire thing is commented out (i.e. put ''' at the front and end''')

Restarted again and removed the stuff I had added to cmdline.txt earlier and it worked just as good as it was before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.