Nathan1258
Posts: 8
Joined: Wed Jun 12, 2019 8:49 pm

Reboot raspberry pi and run a script after

Fri Jun 14, 2019 3:33 pm

Hi, I’m making an application in Python and my script runs some terminal commands via “os.system”. However, after them commands are run, the Pi needs to reboot to make the changes happen. I need to carry on running the rest of the script once the Pi reboots, how would I do that? Basically how do I continue running the script once the pi has rebooted again?

Thanks,
Nathan

dl324
Posts: 107
Joined: Mon May 06, 2019 7:33 pm
Location: Pacific Northwest, USA

Re: Reboot raspberry pi and run a script after

Fri Jun 14, 2019 3:49 pm

Nathan1258 wrote:
Fri Jun 14, 2019 3:33 pm
Basically how do I continue running the script once the pi has rebooted again?
Can't be done. You can start the script automatically at reboot, but you can't have it resume. The current state can't be maintained across boots.

B.Goode
Posts: 7719
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Reboot raspberry pi and run a script after

Fri Jun 14, 2019 4:05 pm

Nathan1258 wrote:
Fri Jun 14, 2019 3:33 pm
Hi, I’m making an application in Python and my script runs some terminal commands via “os.system”. However, after them commands are run, the Pi needs to reboot to make the changes happen. I need to carry on running the rest of the script once the Pi reboots, how would I do that? Basically how do I continue running the script once the pi has rebooted again?

Thanks,
Nathan

Maybe break the script into two : pre-boot and post-boot. Arrange for the post-boot element to be run automatically after a reboot.

Or re-examine your assumption that the entire system needs to be rebooted to enable the configuration changes you are making: maybe just the process or sub-system involved needs restarting?

Andyroo
Posts: 2864
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Reboot raspberry pi and run a script after

Fri Jun 14, 2019 4:08 pm

Get the first part to check for a file on the SD card.

If it’s not present, run the first part, create the file and do a clean reboot
If it’s present, run the second part and delete the file
Need Pi spray - these things are breeding in my house...

Nathan1258
Posts: 8
Joined: Wed Jun 12, 2019 8:49 pm

Re: Reboot raspberry pi and run a script after

Sat Jun 15, 2019 8:47 am

Andyroo wrote:
Fri Jun 14, 2019 4:08 pm
Get the first part to check for a file on the SD card.

If it’s not present, run the first part, create the file and do a clean reboot
If it’s present, run the second part and delete the file
Yep. I went for that idea. I just have a normal file with either ‘true’ or ‘false’ in and do whatever depending on that.

Andyroo
Posts: 2864
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Reboot raspberry pi and run a script after

Sat Jun 15, 2019 12:27 pm

When using Windows I had a lot of code handling the old style ini files. Imagine my pleasure to find the config parser module for Python https://docs.python.org/3.7/library/configparser.html

First tine I read up on this was for a background program that had been hard coded for a given job and every time I wanted a new action I coded it in :oops: it’s now driven by the file contents and a lot easier to add bits in :D
Need Pi spray - these things are breeding in my house...

Return to “Beginners”