What's new

wan-event dynamic script

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

corcoran

New Around Here
Hi folks,

I've got a wan-event script that pushes to pushover, but it won't execute a curl to get my 'real ip' - am I missing something? The script runs OK on reboot, just don't get the output. If I put the environment variable wan_fake_ip, that prints OK; but can't get it to push wan_from_curl nor wan_real_ip into the script.

#!/bin/sh export wan_from_curl="$(curl -fs4 http://ipconfig.io/)" export wan_real_ip="$(nvram get wan0_realip_ip)" export wan_fake_ip="85.63.35.192" asusadmin@RT-AX88U-8FD0:/jffs/scripts# cat wan-event #!/bin/sh . /jffs/scripts/pushover_creds.sh . /jffs/scripts/get_wan.sh push_message(){ echo "Pushover Init" curl -s \ --form-string "token=$pushover_token"\ --form-string "user=$pushover_user"\ --form-string "message=WAN Reconnect Successful at $wan_real_ip"\ https://api.pushover.net/1/messages.json } if [ "$2" = "connected" ]; then push_message else echo $wan_real_ip fi
 
I believe that after a wan-event is triggered it doesn't mean that you already have wan access. Sometimes it takes a few seconds (or longer?) to actually have a working connection again. So immediately executing commands that rely on connectivity are probably not going to work. Try building in a delay, or use a cron to execute the script a minute or 2 after the wan-event happened.
 
Yes, I would say you want to evaluate the two arguments passed and wait for $1 =0 and $2 = "connected"
Here is a log extract that shows a WAN event sequence - there can be several loops thru the process before you get connected.

May 5 00:09:30 gate rc_service: wanduck 1507:notifty_rc restart_wan_if 0
May 5 00:09:30 gate custom_script: Running /jffs/scripts/service-event (args: restart wan_if)
May 5 00:09:30 gate custom_script: Running /jffs/scripts/wan-event (args: 0 stopping)
May 5 00:09:30 gate custom_script: Running /jffs/scripts/wan-event (args: 0 disconnected)
May 5 00:09:30 gate custom_script: Running /jffs/scripts/wan-event (args: 0 stopped)
May 5 00:09:30 gate custom_script: Running /jffs/scripts/wan-event (args: 0 stopped)
May 5 00:09:30 gate custom_script: Running /jffs/scripts/wan-event (args: 0 init)
May 5 00:09:31 gate custom_script: Running /jffs/scripts/wan-event (args: 0 connecting)
May 5 00:09:31 gate custom_script: Running /jffs/scripts/wan-event (args: 0 disconnected)
May 5 00:09:31 gate custom_script: Running /jffs/scripts/wan-event (args: 0 stopped)
May 5 00:12:21 gate custom_script: Running /jffs/scripts/wan-event (args: 0 connected)
 
Last edited:
Cheers both - it's more that I cannot pass real_wan_ip into the script. I don't understand why Merlin keeps using wan_ip (which may not be correct) rather than real_wan_ip in places (like the UI)
 
Try backtics ` (to the left of the 1 key)

export wan_real_ip="$(nvram get wan0_realip_ip)"
export wan_real_ip=`"$(nvram get wan0_realip_ip)"`
or maybe
export wan_real_ip=`$(nvram get wan0_realip_ip)`

NOT the single quote!!!
 

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