What's new

Contribution: update-notification 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!

jtp10181

Senior Member
This works on firmware 380.65 +

Script goes in /jffs/scripts/ and must be executable
Script name is: update-notification

Somewhere in the release thread I think Merlin posted a sample script and I took that and tweaked it and made it more versatile. I thought it was to the point to be worth sharing. It works for an ISP SMTP server which often does not require a login because they can see you are on their network.

You just need to fill in the blanks in the top two sections, should be self explanatory.

NOTE: If you do not use SSL passwords are sent in plain text. I have it setup to always try SSL, but if you set ForceSSL="1" curl will halt if it cannot make a secure connection.

You can test if it works by manually executing the script from command line. And you also add -v to the end of the curl command to see verbose output while testing if you are having issues.

Code:
#!/bin/sh

# SMTP parameters
SMTP="smtp.mailserver.com"
PORT="25"
ForceSSL="0"
USERNAME=""
PASSWORD=""

# Mail Enveloppe
FROM_NAME="$(nvram get computer_name) Router"
FROM_ADDRESS="from_email@mailserver.com"
TO_NAME="Your Name"
TO_ADDRESS="destination_email@whatever.com"


### Do not change below

# Retrieve version
VERS=$(nvram get webs_state_info | sed -E "s/.*([0-9]{3})_([0-9_]+?).*/\1.\2/")
ROUTER_IP=$(nvram get lan_ipaddr)
ROUTER_NAME=$(nvram get computer_name)
CUR_VERS=$(nvram get buildno)_$(nvram get extendno)


echo "From: \"$FROM_NAME\" <$FROM_ADDRESS>" > /tmp/mail.txt
echo "To: \"$TO_NAME\" <$TO_ADDRESS>" >> /tmp/mail.txt
echo "Subject: New router firmware notification" >> /tmp/mail.txt
echo "" >> /tmp/mail.txt
echo "New firmware version $VERS is now available for your router: $ROUTER_NAME / $ROUTER_IP" >> /tmp/mail.txt
echo "Current installed firmware version is: $CUR_VERS" >> /tmp/mail.txt
echo "" >> /tmp/mail.txt
echo "https://asuswrt.lostrealm.ca/" >> /tmp/mail.txt

if [ "$ForceSSL" == "1" ]; then
  FSSL="--ssl-reqd --insecure"
fi

if [ "$USERNAME" != "" ]; then
  USRPW="--user $USERNAME"
  if [ "$PASSWORD" != "" ]; then
    USRPW="$USRPW:$PASSWORD"
  fi
fi

#Send email with cURL
curl --url "$SMTP:$PORT" --ssl $FSSL $USRPW \
  --mail-from "$FROM_ADDRESS" --mail-rcpt "$TO_ADDRESS" \
  --upload-file /tmp/mail.txt

#cat /tmp/mail.txt
rm /tmp/mail.txt
 
Last edited:
sure i can add an option for versatile thats easy enough to do

ill take peak at your script see what relevant and then merge it :)
 
Updated the line(s) that format the web state version in the main post, something changed and broke the old method. New one is more versatile and should handle it well going forward.
 
Why is the —insecure flag enabled? Are ISPs mailservers not expected to use valid certs?
 
Why is the —insecure flag enabled? Are ISPs mailservers not expected to use valid certs?

I believe that was inherited from the original example posted. I just checked and ab-solution is using the same option also.

You could always take that out and try without it. I don't recall if I tested that or not, it's been a while.


Sent from my iPhone using Tapatalk
 

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