User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 426,816 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,882 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 617 | Replies: 3 | Solved
Reply
Join Date: Nov 2007
Posts: 122
Reputation: k2k is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
k2k k2k is offline Offline
Junior Poster

mailx & heredoc

  #1  
Jul 17th, 2008
hi,
can anyone give me a brief example using mailx and heredoc to send an email?


#!/bin/sh
mail -s "subject" target@address >>body
hello all,
          this is supposed to be the body of the mail
body

-----------------------------------------> i think i need somethink like above code, with mailx instead of mail -s......... please correct me
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 275
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: mailx & heredoc

  #2  
Jul 17th, 2008
Hey There,

You should be good to go with just a little change-up:

cat <<EOF | mailx -s "subject" target@address
hello all,
this is supposed to be the body of the mail
EOF

Hope that helps you out

, Mike
Last edited by eggi : Jul 17th, 2008 at 10:50 pm. Reason: typo
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: Nov 2007
Posts: 122
Reputation: k2k is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
k2k k2k is offline Offline
Junior Poster

Re: mailx & heredoc

  #3  
Jul 17th, 2008
Originally Posted by eggi View Post
Hey There,

You should be good to go with just a little change-up:



Hope that helps you out

, Mike



Mike,
thanks again, and it surely works. Would you explain a little bit of what you have done?

cat <<EOF | mailx -s "subject" target@address
is it like, you cat whatever in the new file EOF which contains the "mailx -s ..... " does the | works just like the regular | does? thanks
Reply With Quote  
Join Date: Oct 2007
Posts: 275
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: mailx & heredoc

  #4  
Jul 18th, 2008
Hey, no problem, glad I could help out

The syntax of this is a little confusing, even to me if I just give it a quick glance. But so many things with Linux/Unix are until you get used to them

Basically, I'm catting everything up to the EOF delimiter (which could have been called anything like END or something) and piping all that to mailx, like a regular pipe (|)

The confusing part is the input/output on the same line:

cat <<EOF |mailx -s blah@blah.com

It's equivalent to sending output to a file, which looks like it makes more sense, even though it's the exact same principle

cat << EOF >OUTFILE
sometext
EOF

except instead of dumping the output from after the cat command up to EOF into a file, we're piping it to mailx.

Does that make sense? When you've done it enough times it seems harder to explain it

Best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 8:15 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC