Welcome to WebmasterWorld Guest from 54.227.110.209

Forum Moderators: bakedjake

Message Too Old, No Replies

SendEmail and pipes

can data be piped into sendemail?

     

dstiles

9:44 pm on Feb 14, 2014 (gmt 0)

WebmasterWorld Senior Member dstiles is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Note: sendEmail not sendmail...

I'm trying to pipe the output of a program (specifically urlwatch) into sendemail:

urlwatch | sendemail (options)

I can't find out how to do this and suspect it's not possible, in which case I suppose I'll have to call a script to do it. :(

Anyone have experience of piping programs to command-line emailers?

phranque

1:54 am on Feb 15, 2014 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



pipes work with STDOUT and STDIN so if those programs aren't using standard file descriptors for I/O pipes won't work.

dstiles

7:51 pm on Feb 15, 2014 (gmt 0)

WebmasterWorld Senior Member dstiles is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Thanks. I know urlwatch sends to stdout (message appears in terminal if no pipe) and sendemail uses stdin if there is no -m argument. :(

Your reference to stdin/out spurred me to search for those terms in conjunction with sendemail and I found the suggestion to use $1 for the message body (ie: -m $1). This resulted in an empty body, though. I tried $0 and it emailed me "bash" (this is from the Mint terminal). In case the first line was blank I also tried $2 and $3 but to no avail: always emailed blank body.

I've tried running it as a cron job without -m (as well as with) but got two emails each time, regardless of whether or not urlwatch detected an error. The first email is blank, the second (to postmaster), gives the text I was receiving from running it in the terminal...

=====
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.

Feb 15 19:51:02 mail sendemail[20531]: Message input complete.
Feb 15 19:51:02 mail sendemail[20531]: Email was sent successfully!
=====

I suspect the error may be due to no Ctrl-D, which I cannot enter in this way. As I said, I think the answer is a tailored script. Or possibly an intermediate temp file. :(

dstiles

8:29 pm on Feb 19, 2014 (gmt 0)

WebmasterWorld Senior Member dstiles is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Finally got this working. As I secretly suspected, it was me! :(

I was piping urlwatch into sendemail, which worked in terminal (though without the expected email body text). Following a couple of online examples I used the piping mechanism (urlwatch into sendemail) in cron. Which gave me the same result without telling me WHAT had failed and emailing me even when there was no error.

Looking deeper into it and searching for cron examples rather than urlwatch or sendemail, I came across a useful site that (mostly by inference) guided me to setting up cron correctly. The essencce was: there is no need to specifically email through cron: by default it emails on error. The cron line I am now using is...

1,11,21,31,41,51 * * * * userurlwatch -e

This checks a list of sites every 10 minutes. If there is no error I get no email (a minor problem should the local mail server go down). If there is an error or I've added a new URL I get an appropriate email listing all the erratic or new URLs.

The useful page was at...
www[.]thegeekstuff[.]com/2009/06/15-practical-crontab-examples/

I now have to see if it will also check mail servers.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month