What's new

How to start srcript automatically after reboot (RT-AC86U)

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

jwierzbo

New Around Here
I would like to run automatically after every reboot my custom script e.g. /jffs/myscript.sh
Is it possible with official AsusWRT firmware (Merlin firmware has such a feature)?
 
Yes, look at the documentation readily available.
 
From telnetting in with putty
In my factory firmware I can issue

nvram show | grep jffs | sort -u

and get back this

jffs2_exec=
jffs2_on=1

While telnetted in, issue the command
nvram set jffs2_exec=/jffs/myscript.sh
then issue
nvram commit
so it will stay persistent after reboots and will be rerun at every boot.
 
Last edited:
[/QUOTE]
Could you provide any links?


From telnetting in with putty
In my factory firmware I can issue

nvram show | grep jffs | sort -u

and get back this

jffs2_exec=
jffs2_on=1

While telnetted in, issue the command
nvram set jffs2_exec= /jffs/myscript.sh
then issue
nvram commit
so it will stay persistent after reboots and will be rerun at every boot.

Thanks this is what i was looking for!
Is there any documentation for it (and for others features which I'm not aware yet)?
 
You are welcome.
I am not aware of any specific documentation and can provide no links.
What I know, was not found in my users manual.
I have provided enough information for you to be a danger to your system.

What was given should be plenty to get you started down that path.
 
While telnetted in, issue the command...
I have provided enough information for you to be a danger to your system.
Speaking of dangerous, if your firmware supports telnet, you should disable it in the GUI and only use ssh. You can use putty to open an ssh session. I'm on Merlin and I no longer see a telnet option in the GUI. IDK if it is the same with ASUS firmware.
Also, unless you have a very real reason to modify your router's settings via internet, make sure it is set for LAN Only. There's a few more settings you can do to harden your router's security, but this is the main loophole.
 
Speaking of dangerous, if your firmware supports telnet, you should disable it in the GUI and only use ssh. You can use putty to open an ssh session. I'm on Merlin and I no longer see a telnet option in the GUI. IDK if it is the same with ASUS firmware.
Also, unless you have a very real reason to modify your router's settings via internet, make sure it is set for LAN Only. There's a few more settings you can do to harden your router's security, but this is the main loophole.

Oh , Definitely ! I would NOT be telnetting in through the internet or using the HTTP connection from an external connection.
I don't have any services running that are accessible on external ports.
I'm running stock fw 382_50702 on an RT-N66U.
Using the GUI, the only CLI option is Telnet. But it's not accessible externally unless I open a pinhole, and that's not happening.
HTTP and HTTPS are both available but , like I said , no external services running.

I don't have a need to scp files to or from my router, so installing an sshd daemon in it, just to connect and configure from my LAN or intranet, isn't really necessary - for me.

Thanks for looking out for me though.
 
nvram set jffs2_exec=/jffs/myscript.sh
then issue
nvram commit
so it will stay persistent after reboots and will be rerun at every boot.

I've checked it today and it doesn't not work on my RT-AC86U (with newest firmware: 3.0.0.4.386_40451).
Script is not executed after router restart:

Bash:
$ ssh x.x.x.x
$ cat /jffs/scripts/dnsmasq.sh
#!/bin/sh
echo "test" > /jffs/scripts/test.txt
killall dnsmasq
dnsmasq --no-poll --log-async -c 1500

$ nvram show | grep jffs
jffs2_enable=1
jffs2_exec=/jffs/scripts/dnsmasq.sh
jffs2_format=0
jffs2_on=1
log_path=/jffs

$ reboot
$ ssh x.x.x.x
$ ls -la /jffs/scripts/
.               ..              dnsmasq.sh      dnsmasq.sh.bac

$ ps | grep dns
 1367 nobody    2364 S    dnsmasq --log-async
 1368 jwierzbo  2364 S    dnsmasq --log-async
 2613 jwierzbo  3096 S    grep dns
 
I have to ask, is /jffs/scripts/dnsmasq.sh set to be executable?
There might be other issues with some ASUS firmware. I remember there was a change that caused the X attribute to be removed from jffs files, as a security precaution, during a boot. IDK if that applies to your 386 firmware. If the X attribute is disappears after a reboot, there is a workaround, but check first to see if that is your problem.
 
Last edited:
Maybe your script doesn't have the correct format or permissions?
Code:
dos2unix /jffs/scripts/dnsmasq.sh
chmod 755 /jffs/scripts/dnsmasq.sh
 
Did you reboot and see if the 'X' attrib is still set?
Asus had made some changes a while back and I'm not even sure if nvram set jffs2_exec still works.

The workaround uses a different nvram tag that lets us specify a command to be executed when a USB device is mounted. In this example, I have a script named /jffs/myasusrouter.sh which does some housekeeping and schedules my other scripts. But this requires that some USB storage device be mounted. If you don't currently use USB, just put a formatted memory stick in the port and leave it there. It will be detected every reboot.
Code:
nvram set script_usbmount="chmod 700 /jffs/*.sh;/jffs/myasusrouter.sh"

Since a USB mount can happen during normal operation, it is wise to put some defensive logic in your script to prevent the guts from running multiple times.
So myasusrouter.sh starts with:
Code:
#!/bin/sh
# next line stops script if it has already been run since reboot
mkdir  /tmp/asusrouterlock 2> /dev/null || exit
# the rest of the script....

BTW. this method does not interfer with Merlin scripts, if you should ever care to switch. But there are cleaner ways to run scripts under Merlin.
 
Last edited:
Maybe the jffs2_exec option doesn't work any more. I know that option is disabled in Merlin's firmware, but I don't know whether he did that or it was carried over from Asus.
 
I don't think that variable is enabled anymore in the stock firmware, as it was a security liability.

Note that this would be useless to customize dnsmasq anyway. The instant dnsmasq gets (re)started, any change would then be lost.
 
I've checked it today and it doesn't not work on my RT-AC86U (with newest firmware: 3.0.0.4.386_40451).
Script is not executed after router restart:

Bash:
$ ssh x.x.x.x
$ cat /jffs/scripts/dnsmasq.sh
#!/bin/sh
echo "test" > /jffs/scripts/test.txt
[B]killall dnsmasq[/B]
dnsmasq --no-poll --log-async -c 1500

$ ps | grep dns
1367 nobody    2364 S    dnsmasq --log-async
1368 jwierzbo  2364 S    dnsmasq --log-async
2613 jwierzbo  3096 S    grep dns

Realizing there would be differences between the stock FW I run on my RT-N66U and what is current on newer hardware ,
I have found that killing dnsmasq with grace notifies the watchdog service that dnsmasq has stopped and will restart it instantly.
As RMerlin has stated, when the routers instance of dnsmasq is run it wipes out any previous configuration.
To stop this behaviour, after adding my options to /etc/dnamasq.conf , I forcibly kill dnsmasq and restart it again with
killall -9 dnsmasq && dnsmasq

The jffs partition could be getting mounted and the script is run before dnsmasq is started by the system.
If it were a "race condition" you may be winning the race to start dnsmasq but not killing anything because it hasn't started yet.
I let my router write its version of the config file, starting dnsmasq, before I add my options. Then I forcibly kill dnsmasq and restart it.
When the router instance of dnsmasq gets run it also overwrites any configuration changes I've made.
My scripts reside on removable media, not in the jffs partition. Hence they are run about 4 seconds later in the boot process.

Not having the config file written yet probably explains why it is running as your login instead of as nobody.

I haven't played with newer firmware than stock 382 or non stock firmware.
So any advice RMerlin provides would most certainly override any I could give.
 
Last edited:
is there still no working way to start a script from poweron or reboot.

my current router uses johns fork and with that (or merlins versioons it easy)

my new router is an RT-AX88u with the latest stock FW 3.0.0.4.384_9579
i could not find anything about jffs in the setup but it seems enabled by default

now the hard part seems to be to start a custom script at bootup.
all previous mentioned examples do not seem to work
 
Use RMerlin firmware, not stock.
 
yes but Merlin does not seem to be that stable with latest builds (hanging gui's)

coming from john's fork and experiencing strange wifi issues i need something very stable
 
question regarding this
mkdir /tmp/asusrouterlock 2> /dev/null || exit will create a dir and if it is created again it will generate an error and exit
will this directory be removed after every reboot?




Did you reboot and see if the 'X' attrib is still set?
Asus had made some changes a while back and I'm not even sure if nvram set jffs2_exec still works.

The workaround uses a different nvram tag that lets us specify a command to be executed when a USB device is mounted. In this example, I have a script named /jffs/myasusrouter.sh which does some housekeeping and schedules my other scripts. But this requires that some USB storage device be mounted. If you don't currently use USB, just put a formatted memory stick in the port and leave it there. It will be detected every reboot.
Code:
nvram set script_usbmount="chmod 700 /jffs/*.sh;/jffs/myasusrouter.sh"

Since a USB mount can happen during normal operation, it is wise to put some defensive logic in your script to prevent the guts from running multiple times.
So myasusrouter.sh starts with:
Code:
#!/bin/sh
# next line stops script if it has already been run since reboot
mkdir  /tmp/asusrouterlock 2> /dev/null || exit
# the rest of the script....

BTW. this method does not interfer with Merlin scripts, if you should ever care to switch. But there are cleaner ways to run scripts under Merlin.
 

Latest threads

Sign Up For SNBForums Daily Digest

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