What's new

How to autorun python script at router boot?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

piedpiper

New Around Here
Hi all, I have been making a script so DNS Filtering is turned on/off depending on pihole being up/down. That way if I reboot my server the router automatically disables DNS Filtering and the other devices are able to resolve DNS.

At first I wrote it in C, but I haven't been able to compile it for my router (AC3200), then I decided to re-write it in Python and it runs fine but I'm not able to make it start at boot. Anyone that can point me in the right direction? I tried putting the script in /jffs/scripts with the right permissions but doesn't run. Also I have been searching this forum and google but couldn't find an answer.

Thanks!
 
Welcome to the forums @piedpiper.

Have you had a look in the link below?

 
Welcome to the forums @piedpiper.

Have you had a look in the link below?

Thanks for the reply. Yes, I tried adding a line to start the script in start-services but doesn't start at boot. Also tried adding @reboot option in crontab.
 
As the router doesn't have python included as part of the firmware I'm assuming you've added it through Entware? As such Entware services should be started and stopped by creating an "S" script in /opt/etc/init.d/ (e.g. S99myscript).
 
As the router doesn't have python included as part of the firmware I'm assuming you've added it through Entware? As such Entware services should be started and stopped by creating an "S" script in /opt/etc/init.d/ (e.g. S99myscript).
This was it! now it's working. Thank you so much. I will test it and then share the script in case anyone finds it useful
 
As the router doesn't have python included as part of the firmware I'm assuming you've added it through Entware? As such Entware services should be started and stopped by creating an "S" script in /opt/etc/init.d/ (e.g. S99myscript).
Technically .sh scripts will work as well. However for priority sake, the S and # number part of the script title indicates priority of the run, otherwise everything else that is .sh (e.g. myscript.sh) naming runs alphabetically after.
 
Technically .sh scripts will work as well. However for priority sake, the S and # number part of the script title indicates priority of the run, otherwise everything else that is .sh (e.g. myscript.sh) naming runs alphabetically after.
Actually that's not the case. Although there is redundant code in rc.unslung to suggest that's probably how it worked in the past.

The scripts are selected on the -perm '-u+x' -name 'S*' clause in the find command. So even though the case statement has patterns for *.sh and * they will never be matched (unless they also happen to begin with 'S').
 
Actually that's not the case. Although there is redundant code in rc.unslung to suggest that's probably how it worked in the past.

The scripts are selected on the -perm '-u+x' -name 'S*' clause in the find command. So even though the case statement has patterns for *.sh and * they will never be matched (unless they also happen to begin with 'S').
That's good to know for future reference.
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top