What's new

order of execution of startup-scrips

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

Martin - SNBuser

Regular Contributor
Hi,

I created all of these files (instructions here: https://github.com/RMerl/asuswrt-merlin/wiki/User-scripts ):
Code:
services-stop
wan-start
firewall-start
nat-start
init-start
pre-mount
post-mount
unmount
dhcpc-event
openvpn-event
ddns-startb
Some of these I really use (nat-start and firewall-start). All files starts with:
Code:
#!/bin/sh
logger -t "$0" "Hey, I'm working - in /jffs/scripts/..."
When I look in /tmp/syslog I only see two lines with "Hey, I'm working...":
Code:
...
Sep 29 23:46:40 start_nat_rules: apply the nat_rules(/tmp/nat_rules_eth0_eth0)!
Sep 29 23:46:41 custom script: Running /jffs/scripts/nat-start
Sep 29 23:46:41 /jffs/scripts/nat-start: Hey, I'm working - in /jffs/scripts/...
Sep 29 23:46:41 custom script: Running /jffs/scripts/firewall-start (args: eth0)
Sep 29 23:46:41 /jffs/scripts/firewall-start: Hey, I'm working - in /jffs/scripts/...
...
I wanted to see, which is the last of these scripts - and then in the last executed user-script, I wanted to run:
Code:
iptables-save > /tmp/iptables-save.txt
Then I can always easily revert to the iptables, from the last reboot...

My problem is that I don't see logging in any other file than firewall-start and nat-start (maybe because I have real commands in these scripts)? I don't understand why there are not more "Hey, I'm working"-lines in my syslog? I thought if these files where present, the "logger -t ....."-command would always be run, despite that there's nothing else in these files...? Any comments?
 
Some of the scripts are event triggered. So, for example, dhcpc-event will only run when a DHCP client connects. Others like post-mount will only run if you have USB drive attached.
 
Hi,

I created all of these files (instructions here: https://github.com/RMerl/asuswrt-merlin/wiki/User-scripts ):
Code:
services-stop
wan-start
firewall-start
nat-start
init-start
pre-mount
post-mount
unmount
dhcpc-event
openvpn-event
ddns-startb
Some of these I really use (nat-start and firewall-start). All files starts with:
Code:
#!/bin/sh
logger -t "$0" "Hey, I'm working - in /jffs/scripts/..."
When I look in /tmp/syslog I only see two lines with "Hey, I'm working...":
Code:
...
Sep 29 23:46:40 start_nat_rules: apply the nat_rules(/tmp/nat_rules_eth0_eth0)!
Sep 29 23:46:41 custom script: Running /jffs/scripts/nat-start
Sep 29 23:46:41 /jffs/scripts/nat-start: Hey, I'm working - in /jffs/scripts/...
Sep 29 23:46:41 custom script: Running /jffs/scripts/firewall-start (args: eth0)
Sep 29 23:46:41 /jffs/scripts/firewall-start: Hey, I'm working - in /jffs/scripts/...
...
I wanted to see, which is the last of these scripts - and then in the last executed user-script, I wanted to run:
Code:
iptables-save > /tmp/iptables-save.txt
Then I can always easily revert to the iptables, from the last reboot...

My problem is that I don't see logging in any other file than firewall-start and nat-start (maybe because I have real commands in these scripts)? I don't understand why there are not more "Hey, I'm working"-lines in my syslog? I thought if these files where present, the "logger -t ....."-command would always be run, despite that there's nothing else in these files...? Any comments?
A couple of things.....
The 'custom script: Running'..... syslog is generated by the firmware and should be there for each of your scripts. If it's not, it means the firmware isn't finding the script. Check that they are named correctly.
If that syslog is there, most likely the scripts are saved in DOS/WIN format, and not in Linux format. Run dos2unix on each of the scripts.
 
Some of the scripts are event triggered. So, for example, dhcpc-event will only run when a DHCP client connects. Others like post-mount will only run if you have USB drive attached.
Oh, thanks - maybe I also read that. It just surprised me, that only two of the files apparently ran... I guess it means that many of these scripts apparently do not even run on my router... That makes sense... I could see /jffs/scripts/firewall-start is the last that ran, from syslog. So in the last line of
/jffs/scripts/firewall-start I think I'll just add "iptables-save > /tmp/iptables-save.txt"... Thanks a lot - time to do some iptables-experimenting!

To john9527 Part of the Furniture: The scripts was made on the router - so I don't think it has anything to do with DOS/UNIX end of line-characters... But thanks a lot anyway...
 
The ones in /jffs/scripts/ also need to be set to executable, make them 0755, or if you prefer:
chmod a+rx /jffs/scripts/*
 
To thelonelycoder: The scripts are already all executables, so that is not the problem....
To octopus: That is really great, thank you very much for this list of ordered scripts... I used this list to insert "iptables-save > /tmp/iptables-save.txt" into /jffs/scripts/post-mount. It kind of seemed to work (because the file HAS been generated and DOES exist under /tmp). However, I found something disturbing: It seems like the command "logger -t "$0" "Hey, I'm working - in /jffs/scripts/..."" didn't write that post-mount was executed... But based on the fact the the iptables-save.txt file was found under /tmp it must have been ran... I'm thinking: Could it have anything to do with any of the scripts calling entware-executables? It's kind of strange, I think...
 
The post-mount script will be executed every single time a USB disk is plugged. Do not use it for manipulating firewall rules, as 1) it won't be re-executed if you change a setting that causes the firewall to be reconfigured, and 2) it might be re-executed multiple times.

There's no such thing as a "sequential order" as previously mentioned - use the appropriate location based on what you are doing.
 
The post-mount script will be executed every single time a USB disk is plugged. Do not use it for manipulating firewall rules, as 1) it won't be re-executed if you change a setting that causes the firewall to be reconfigured, and 2) it might be re-executed multiple times.

There's no such thing as a "sequential order" as previously mentioned - use the appropriate location based on what you are doing.
Thanks Merlin! My fear was I had done something wrong as I could only see /jffs/scripts/nat-start and /jffs/scripts/firewall-start scripts running... So last command of firewall-start is my command to run "iptables-save > /tmp/file.txt" so I can always easily get back to the immediate "after-bootup"-configuration... Thanks!
 

Similar threads

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