What's new

My WAN2 IP email script almost works but not quite, any idea's where I have chuffed up?

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

lukeglazebrook

Occasional Visitor
I stole the below script and it works great, with the exception that I have tweaked it slightly in the hope that it will report my WAN2 USB address when a failover event occurs. I changed the highlighted bit below...

Unfortunately however I don't get a valid IP address when the email report arrives. Any idea why that might be?


#!/bin/sh
touch /tmp/want-start
FROM="luke@gmail.com"
AUTH="lukegmail.com"
PASS="********"
FROMNAME="RTAC88U ROUTER"
TO="luke@gmail.com"

ntpclient -h pool.ntp.org -s &> /dev/null
sleep 5

echo "Subject: WAN state notification" >/tmp/mail.txt
echo "From: \\"$FROMNAME\\"<$FROM>" >>/tmp/mail.txt
echo "Date: `date -R`" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "I just got connected to the internet." >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "My WAN IP is: `nvram get usb0_ipaddr`" >>/tmp/mail.txt
echo "Uptime is: `uptime | cut -d ',' -f1 | sed 's/^.\{12\}//g'`" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "---- " >>/tmp/mail.txt
echo "Your friendly router." >>/tmp/mail.txt
echo "" >>/tmp/mail.txt

cat /tmp/mail.txt | sendmail -H"exec openssl s_client -quiet \
-CAfile /jffs/configs/Equifax_Secure_Certificate_Authority.pem \
-connect smtp.gmail.com:587 -tls1 -starttls smtp" \
-f"$FROM" \
-au"$AUTH" -ap"$PASS" $TO

rm /tmp/mail.txt

Unfortunately however I don't get a valid IP address when the email report arrives. Any idea why that might be? See example below...

"I just got connected to the internet.

My WAN IP is:
Uptime is: 0 min

----
Your friendly router."
 
Last edited:
My WAN1 IP address is nvram var "wan0_ipaddr", so won't the WAN2 IP address be "wan1_ipaddr" ?

I hope that's not your real gmail address and password in that post!
 
I tried that first of all mate but with "wan1_ipaddr" I get the following email back (no actual IP) ...

I just got connected to the internet.


My WAN IP is: 0.0.0.0

Uptime is: 36 min

----

Your friendly router.
 
You can always look into the email header in gmail to find what IP was used!

From command line

nvram show

will display all nvram vars

nvram show | grep ipaddr

will list only those with ipaddr in the name
 
Similar threads
Thread starter Title Forum Replies Date
W Abuse email from ISP ASUS Wireless 26
C Script to notify unknown device connects to LAN ASUS Wireless 3

Similar threads

Latest threads

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!

Members online

Top