What's new

Where should I put a script to take effect after all events?

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

cjgarmar

New Around Here
Hi all!

I've just bought an ASUS AC56U router and I've installed Asuswrt-Merlin v374-40. After reading a lot of posts, I set up Optware, Internet connection through Cisco VPN and I also share Internet vpn connection from LANs hosts, but I can't make the scripts persistent. Let me explain:

I've got a script called /jffs/scripts/services-start, with this code...

#!/bin/sh
/opt/etc/config/vpnc/startup-script
sleep 10
/opt/etc/config/vpnc/firewall-start

The "/opt/etc/config/vpnc/startup-script" script makes Cisco VPN connection possible and the "/opt/etc/config/vpnc/firewall-start" script has this code...

#!/bin/sh
iptables -F
iptables -t nat -F
iptables -A FORWARD -o tun0 -j ACCEPT
iptables -A FORWARD -i tun0 -j ACCEPT
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

If I manually start "/jffs/scripts/services-start" script, all is working ok. But, if I reboot router to try starting it automatically, neither vpnc nor iptables rules take effect. I also tried to use a combination of scripts /jffs/scripts/firewall-start, /jffs/scripts/nat-start, /jffs/scripts/services-start, but none of them seems to boot or it's possible they will occur before something that made them change.

I don't know where should I put the script to have desired configuration. Some help please?

Thank you!

Cristian.
 
Have you followed the User scripts and iptables tips documentation?
It will get you going...
Thanks for replaying, thelonelycoder.

I've followed both documents. But as I said in my post, the scripts aren't working as they should, because...

"I've got a script called /jffs/scripts/services-start"

and...

"If I manually start it, all is working ok."

but...

"if I reboot router to try starting it automatically, neither vpnc nor iptables rules take effect".

So...

"I also tried to use a combination of scripts /jffs/scripts/firewall-start, /jffs/scripts/nat-start, /jffs/scripts/services-start, but none of them seems to boot or it's possible they will occur before something that made them change." Obviously, I decline for second option, that is, I think there must have some daemon that is launching default iptables every some event and services-start is launched before this daemon. So, services-start doesn't take effect.

After all of that, my question is:

Where should I put a script to take effect after all events?

Thanks again!

Cristian.
 
Make sure the file is executable and has a shebang.

chmod +x /path/file
 
Thanks Adamm! I've just detected what's the problem:

I think usb disk is not mounted when services-start script is launched, because I rewrite the script to test the problem with...

#!/bin/sh
/opt/etc/config/vpnc/startup-script 2>/tmp/error_startup.txt
sleep 10
/opt/etc/config/vpnc/firewall-start 2>/tmp/error_firewall.txt

and I get these errors...

/jffs/scripts/services-start: line 3: /opt/etc/config/vpnc/startup-script: not found

/jffs/scripts/services-start: line 3: /opt/etc/config/vpnc/firewall-script: not found


So, it is quite clear that usb is not mounted yet.

I rephrase the question, where should I put a script to take effect after mount disk event?

Thanks!
 
Now we're getting to the bottom of this.
/jffs/scripts/post-mount
Place it after this if you have optware installed:
Code:
#!/bin/sh

if [ $1 = "/tmp/mnt/sda1" ]
then
  ln -sf $1/entware /tmp/opt
fi
 
Last edited:
It would be VERY helpful to know the exact order in which the user scripts execute when the router is booted.

So as not to leave out any of the scripts, let's assume that a USB device is connected, the VPN (Server or Client) is set to "Start with WAN," and the router is finally re-booted once everything has started up.

So... below are the scripts as listed on GitHub. Can someone put them in the proper order? I can figure out some, but not all.

services-start
services-stop
wan-start
firewall-start
nat-start
init-start
pre-mount
post-mount
unmount
dhcpc-event
openvpn-event
 
It's not a static order. That's why there is no such list. Scripts are executed based on specific events, they aren't in one single long list, so it's impossible to predict in which specific order they would run.
 
It's not a static order. That's why there is no such list. Scripts are executed based on specific events, they aren't in one single long list, so it's impossible to predict in which specific order they would run.

Understood.

I guess I should just put "touch /tmp/000[scriptname]started" in each of the user scripts, reboot, and then sort the files by modified time to get an idea of the order in which they execute for me.
 
Thanks all!

After reading all your answers, I've just made some tests and I think it's working as it should. If it's any help, this is what I've done:

1. Create a /jffs/script/post-mount script

(
Comment @Hothersale about that point:

You'd better use that kind of scripting:

Code:
date > /tmp/000[scriptname]started

than yours:

Code:
touch /tmp/000[scriptname]started

If you do that way, you'll get hour/minute/seconds event started
)

2. The content of my post-mount script is

Code:
#!/bin/sh
if [ $1 = "/tmp/mnt/sda8" ] #Optware on my system is on /tmp/mnt/sda8
then
    /opt/etc/config/vpnc/startup-script 
    sleep 10
    /opt/etc/config/vpnc/firewall-start
    sleep 5
    cru a vpncalive "*/15 * * * * /opt/etc/config/vpnc/keep-alive" #I've used the script to start a scheduled script
fi

(
Comment @thelonelycoder: thanks for the script example
)

For now it's working properly.

Kind regards,

Cristian.
 
Hi Cristian,

Very glad to see that you seemed make the vpnc worked on your ac56u, but I have some problem different about vpnc on my ac68u, could you please give me some help?

1 I got a error msg that said lack of dependence when install from Optware. I use "ipkg -nodeps install vpnc" then seems it's OK.

2 I saw the tun tunnel established in "ifconfig" after I ran "vpnc /tmp/disk/vpnc/vpnc.conf", but the problem is I can't access any website through the tunnel.
I have tried ran your "services-start" script or "vpnc-disconnect", but the internet access would not come back.

Do I miss something or if you has any tips?

Thanks.
R.


Hi all!

I've just bought an ASUS AC56U router and I've installed Asuswrt-Merlin v374-40. After reading a lot of posts, I set up Optware, Internet connection through Cisco VPN and I also share Internet vpn connection from LANs hosts, but I can't make the scripts persistent. Let me explain:

I've got a script called /jffs/scripts/services-start, with this code...

#!/bin/sh
/opt/etc/config/vpnc/startup-script
sleep 10
/opt/etc/config/vpnc/firewall-start

The "/opt/etc/config/vpnc/startup-script" script makes Cisco VPN connection possible and the "/opt/etc/config/vpnc/firewall-start" script has this code...

#!/bin/sh
iptables -F
iptables -t nat -F
iptables -A FORWARD -o tun0 -j ACCEPT
iptables -A FORWARD -i tun0 -j ACCEPT
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

If I manually start "/jffs/scripts/services-start" script, all is working ok. But, if I reboot router to try starting it automatically, neither vpnc nor iptables rules take effect. I also tried to use a combination of scripts /jffs/scripts/firewall-start, /jffs/scripts/nat-start, /jffs/scripts/services-start, but none of them seems to boot or it's possible they will occur before something that made them change.

I don't know where should I put the script to have desired configuration. Some help please?

Thank you!

Cristian.
 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

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