Send email when WAN up

Discussion in 'Tomato Firmware' started by rajil_s, May 30, 2010.

  1. rajil_s

    rajil_s Addicted to LI Member

    Hi all,

    I would like to send an email to myself whenever the router WAN is up. I couldnt find any mta on the router so instead i wrote a shell script on a server running behind the router.

    The shell script is basically
    >cat /usr/local/bin/
    'd=`date '+%d/%m/%y_%H:%M:%S'`
    smtp-cli --verbose --user xxx --auth-plain --from  --pass xxxx --to --subject $d
    The smtp-cli is a perl script for sending email from here. I dont understand how to trigger this script sitting on my server from the router. I was hoping that i could simply do a
    ssh myserver " /usr/local/bin/"
    on WAN UP but it seems that dropbear ssh in tomato doesnt support logging in with keys. Is there any other way?

  2. mstombs

    mstombs Network Guru Member

    I have tried a few router-compatible binaries which can send email via my ISP, but not found one yet which works with gmail. The latest BusyBox versions can be compiled with its version of sendmail - just adds a couple of kB.
  3. TexasFlood

    TexasFlood Network Guru Member

  4. TexasFlood

    TexasFlood Network Guru Member

    So I just tried this, finally, :wink:.

    My first test was from my Ubuntu laptop to the Comcast SMTP server which worked fine as shown below, slightly sanitized to remove my personal info, specifically my IP address and my source and destination email accounts. The email was delivered and looked fine.

    When doing from the Tomato router, all is well up until I try to enter the "." to end the data input. The Comcast SMTP server simply won't recognize the "." to end the data input so I can't finish and send the email. Maybe the line end needs to be CR/LF or something and isn't so not recognized, or something else simple like that. I tried a few ideas to get it working but nothing I tried worked as of yet.

    If anyone has an idea what the issue is & how to resolve, I'd sure appreciate a clue.
    telnet 25
    Connected to
    Escape character is '^]'.
    220 comcast ESMTP server ready
    250 hello [{my IP address was removed from here}], pleased to meet you
    mail from:
    250 2.1.0 <> sender ok
    rcpt to:
    250 2.1.5 <> recipient ok
    354 enter mail, end with "." on a line by itself
    subject: test subject line
    Test message line 1
    Test message line 2
    Test message line 3
    Testing, testing, 1, 2, 3, testing
    Test message last line
    250 2.0.0 QGew1e00B0uhdwP3TGfHkj mail accepted for delivery
    221 2.0.0 comcast closing connection
    Connection closed by foreign host.
    I was actually trying to implement the scripted approach as shown below but hit the same issue as doing it interactively. The script actually seems to work, up until the aforementioned "." problem.
    MESSAGE="This is the message"
    SUBJECT="Subject line"
    if (
            sleep $DELAY
            echo "HELO $DOMAINNAME"
            sleep $DELAY
            echo "MAIL FROM: $FROM"
            sleep $DELAY
            echo "RCPT TO: $TO"
            sleep $DELAY
            echo "DATA"
            sleep $DELAY
            echo "Date: $DATETIME"
            echo "From: $FROM"
            echo "To: $TO"
            echo "Subject: $SUBJECT"
            echo "X-Mailer: $MAILERNAME $MAILERVERSION"
            echo ""
            echo "$MESSAGE"
            echo "."
            sleep $DELAY
            echo "QUIT"
            sleep $DELAY
            logger local7.warning -t "smtp_auto_message" "WARNING: condition"
  5. but2002

    but2002 Networkin' Nut Member

    I made my router flash the DMZ light when the WAN comes up.

    What's the purpose of an e-mail?
  6. TexasFlood

    TexasFlood Network Guru Member

    I just wanted the ability to send a notification email on a condition. It's really just another way of logging event information, just more immediate. The condition could be almost anything.

    It could be the WAN coming up as the original poster wanted.
    Could also be:
    • Excessive CPU usage
    • Low memory
    • Run at boot time so you know when the router is rebooted
    • When a ping to a remote router fails, etc.
    Limited only by your needs and imagination.
  7. rajil_s

    rajil_s Addicted to LI Member

    I have a slighlty different scenario. I have the email script all setup on the server attached to tomato. However, i dont know how to trigger that script from the tomato router.
  8. TexasFlood

    TexasFlood Network Guru Member

    If the issue is running the script with SSH, seems like that should work. Maybe something basic preventing it? So if you are SSHing from the router to your server, you're root on the router so assuming ssh is set up correctly will be root on the server. Can you run the script as root directly on the server, have executable permissions etc, are there any required environmental variables, like $PATH that might not get sourced running it this way? Just thinking out loud. I have run scripts on one router from another via SSH successfully and don't see why this should be any different. Should be able to do some tests and troubleshoot it & get it working.

    If the issue is getting the script to work with gmail, I'll pass on that for now as I have no experience with the script & gmail or time to test it right now.
  9. rajil_s

    rajil_s Addicted to LI Member

    The problem is that I dont want to manually specify a password when tomato does a ssh into my server. I have copied the required public key in the .ssh/authorized_keys file of the router.

    However, when i do a ssh from tomato to the server, it never passes the keys to the server and hence the authentication fails down to password entry. Is that a limitation of the ssh client of tomato?
  10. TexasFlood

    TexasFlood Network Guru Member

    So it's an SSH set-up / key exchange issue.

    I had some trouble getting ssh set up correctly. It didn't seem as straightforward as I had hoped, but I did get it working. Actually, with all the upgrades I've been doing on routers and my Ubuntu laptop, it's now broken again but I don't have time to fix it right now. I can SSH between routers but the routers can't get to my Ubuntu box since I upgraded the release.

    I'll have to see if I took any notes when I got it working last time. I hope I did as all of that information has run out of my ears onto the floor, :wink:. If not then I -really- need to make some good notes when I get around to fixing it so it won't be so difficult next time something goes wrong.

    I suggest starting with the "FAQ 'Networking -> Secure Shell (SSH)'" links, as well as outside links for OS specific SSH such as the SSH OpenSSH Advanced page in my case for Ubuntu OpenSSH setup. If you can't sort it out from there, I would suggest starting a new thread with a more targeted title such as "SSH setup problems".
  11. rhester72

    rhester72 Network Guru Member

    To initiate from the router, you'll need to have a private key on the router and use the "-i" option from the busybox ssh client...which will _not_ persist across reboots without some init script magic (very dependent on the approach you use).

    I agree it probably justifies another thread.

  12. TexasFlood

    TexasFlood Network Guru Member

    You just described at least part of what I did.

    I created a private key & public key on each router with dropbearkey. Then after seeing them disappear on reboot, duh, I copied them all to a CIFS share with names indicating the associated router, then after a delay to make sure the CIFS system is up and ready, copy them back to ~/.ssh. Also wrote a little script that is installed in the init tab to allow me to be lazy in typing my ssh commands, called it "ss" and can just type "ss {last octet of an address on my local subnet} {optional command}". Very simple, but a time saver at times, as follows:
    ssh -y -i /tmp/home/root/.ssh/id_rsa 192.168.1.$*
    What I can't clearly remember is seems like there were some interoperability issue between dropbear and openssh that I had to resolve, or at least to achieve a "passwordless" key exchange login. I don't recall clearly, hoping I can find some notes but haven't really had adequate time to fix this yet. I -may- have used dropbearconvert, not sure if that is still needed with recent versions, as well as some openssh utilties but again just don't recall specifics. Although there is a link named dropbearconvert on the router in /usr/lib/dropbear/dropbearconvert , doesn't look like it's really compiled in so I installed dropbear on my Ubuntu box and used dropbearconvert over there for my tests. Anyway, out of time again, :wink:
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice