•
•
•
•
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
![]() |
•
•
Join Date: Nov 2007
Posts: 122
Reputation:
Rep Power: 1
Solved Threads: 0
hi,
can anyone give me a brief example using mailx and heredoc to send an email?
-----------------------------------------> i think i need somethink like above code, with mailx instead of mail -s......... please correct me
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
•
•
Join Date: Oct 2007
Posts: 275
Reputation:
Rep Power: 1
Solved Threads: 26
Hey There,
You should be good to go with just a little change-up:
Hope that helps you out
, Mike
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!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
•
•
Join Date: Nov 2007
Posts: 122
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Oct 2007
Posts: 275
Reputation:
Rep Power: 1
Solved Threads: 26
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:
It's equivalent to sending output to a file, which looks like it makes more sense, even though it's the exact same principle
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

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:
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!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Shell Scripting Forum
- Previous Thread: command to telnet console using shell-script
- Next Thread: Calling GDB commands from Shell


Linear Mode