0

I have OpenWRT router, installed msmtp. I would like to write a command line (or a .sh file) that would send me the current public IP address, and let Cron execute it every 15 Min.

I found the posting: Run a command and email the output

and tried to do the same with msmtp, and it did work: I did the following

kdig +short myip.opendns.com @resolver1.opendns.com | msmtp [email protected]

and got an email with the current public IP address, but without a subject, of course, because I didn't set anything. Now, for msmtp, the way to put a subject is

echo "Subject: Current Public IP" | msmtp [email protected]

But I have no idea how I could combine these two things.... I would appreciate your help very much !

jbweld
  • 1
  • 2

1 Answers1

0

I can't claim credit for this approach. I saw it somewhere else but this little snippet could be improved with checking for parameters and adding them in a more flexible manner but it should get the concept across:

kdig +short myip.opendns.com @resolver1.opendns.com |{
    SUBJ="A Subject"
    echo "From: \"name\"<[email protected]>"
    echo "To: \"me\"<[email protected]>"
    echo "Subject: ${SUBJ}"
    # Now repeat what was piped in 
    cat /dev/fd/0
} | msmtp [email protected]
Bryan
  • 101
  • 1