how can I write a shell to send a mail with subject and content , the default "mail" need to input the content and ended by ctl-d , so it is not I want , I want to fix the address, subject and its content at the shell file.
Actually, you should be able to do the same with mail (instead of using mailx):
mail -s "Shell Generated Mail" steview85 <<-EOF
Hello world
EOF
Note that "EOF" stands for "end of file", but it is just a label here -- you can use another label if you prefer. The script reads as input (<<) until it hits the label indicated by the - and then passes a ctl-d (which is the true end of file - just like you do when you use the mail program interactively).
I don't know what you're trying to do, but knowing that ctl-d is the EOF mark gives you other options. You could write the content out to a file and then send that. Here's an example that demonstrates some possibilities:
rm -f mtmpfile
cat <<-EOF > mtmpfile
hello world
EOF
... command >> mtmpfile
...
mail -s "Mail from file" steview85 < mtmpfile
rm -f mtmpfile
(Of course, you need to ensure you have permission to write to mtmpfile.)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.