Welcome! Log In Create A New Profile

Advanced

How to run a python script at reboot?

Posted by jrey 
How to run a python script at reboot?
January 14, 2021 01:02PM
I am using debian on a dockstar.

Linux dockstar 5.5.1-kirkwood-tld-1 #1.0 PREEMPT Sat Feb 1 22:28:36 PST 2020 armv5tel GNU/Linux

What is the easiest (and clean) way if I want to run a python script at reboot? I have tried editing /etc/rc.local but that did not seem to work.

Thanks.
Re: How to run a python script at reboot?
January 14, 2021 04:35PM
jrey,

> What is the easiest (and clean) way if I want to
> run a python script at reboot? I have tried
> editing /etc/rc.local but that did not seem to
> work.

/etc/rc.local is good for this purpose. Make sure you use the full path for the script. Put it at /root like this.

/root/script_name

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: How to run a python script at reboot?
January 15, 2021 08:07AM
Thanks, bodhi. I have noticed the problem. I am uploading data to adafruit for an IoT sensor. When I ran the script manually, I noticed that I had to wait a few minutes after rebooting debian. If I ran the script too early, I have some kind of error related to authentication with adafruit. Not sure what caused the problem. Is it possible to delay the script a few minutes if I use rc.local? I did run the script automatically on a raspberry pi using crontab with no problem.
Re: How to run a python script at reboot?
January 15, 2021 12:51PM
I'm assuming you're not using systemd, if you were you can set your script to run after the network is up via a "wants=" field.

you should be able to set your script to run have dhcp-client to ensure the network will be up.

it's been a while....but don't you put it in rc.6 with a suitable filename (since they get executed alphabetically)?
Re: How to run a python script at reboot?
January 23, 2021 06:34AM
I think I found the reason why it didn't work before. Every time I reboot the machine, the time gets reset to Jan 1, 1970. It takes about five minutes before it is changed to 2021. After that the script runs ok. My system is

Linux pogoe02 5.5.1-kirkwood-tld-1 #1.0 PREEMPT Sat Feb 1 22:28:36 PST 2020 armv5tel GNU/Linux

So, 1. How do I fix the time resetting problem or how can it correct after reboot faster?
2. How can I time to run the script, let say, 5 or 10 minutes after the system is up?
Re: How to run a python script at reboot?
January 23, 2021 03:40PM
jrey,

> So, 1. How do I fix the time resetting problem or
> how can it correct after reboot faster?

This Pogo E02 does not have RTC. So install fake-hwclock to help with reboot.

apt-get install fake-hwclock

> 2. How can I time to run the script, let
> say, 5 or 10 minutes after the system is up?

Use the at command.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: How to run a python script at reboot?
January 23, 2021 08:07PM
Thanks. That helps.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: