Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to screen and /bin/mail

Status
Not open for further replies.

jouell

MIS
Nov 19, 2002
304
US
Hi.

I have a shell script that will alert me when a new event has happened, basically:

<snip>
printf "A new IP, $IP was blocked from connecting to Port 80\n"
printf "A new IP, $IP was blocked from connecting to Port 80\n" | mail -s "Blacklist Alert" "$RECIPIENT"

What I would like to do is to be able to print to the screen and send an e-mail with the same message.
I want to do something like this:

printf "Sending email saying A new IP, $IP was blocked from connecting to Port 80\n" | mail -s "Blacklist Alert" "$RECIPIENT"

But also have the output sent to the screen as well.

Is it possible to do this *without* creating a named pipe, or any temporary file (using the tee, etc.)? I'd like to solve this with those as solutions, if possible.

Thanks
jouell
 
Why not using the tee command ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry, using tee is fine! I was thinking not using tee -a and
my brain misfired. You actually helped solv my issue by prompting the thought.

Correct solution is:

printf "A new IP was blocked from connecting to Port 80\n" | tee >(mail -s "Blacklist Alert" "$RECIPIENT")

Thanks!
jouell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top