Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
the mail is delivered successfully with the content Test.. how can I add subject to this mail.. such that the mail should get deliver with
the subject.
'echo "Subject: Test" | /usr/sbin/sendmail -t user@host' should work, however using "mail" from the mailx or mail-utils package will be easier ('/bin/true| mail -s "Test" user@host'). If you're going to send attachments from the CLI or a shellscript later on search for "mpack".
'echo "Subject: Test" | /usr/sbin/sendmail -t user@host' should work, however using "mail" from the mailx or mail-utils package will be easier ('/bin/true| mail -s "Test" user@host'). If you're going to send attachments from the CLI or a shellscript later on search for "mpack".
Hai ,
Thanks for the guidance.. above works fine.. but how to add message body ..I want to have both subject and body message for the same.
(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log")
Don't put quotes around this code and it should work. If running from a script you can also consider a more readable "here document", as in
Code:
/usr/sbin/sendmail user@host << EOM
From: Colucix
To: user@host
Subject: Test
$(date)
$(echo "DEV - There are $RETURN_CODE errors in Alert log)
$(any_other_command)
Some text here.
Bye
EOM
The first part of the input to sendmail is to fill the various fields of the e-mail, the rest goes into the mail body.
(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log")
Don't put quotes around this code and it should work. If running from a script you can also consider a more readable "here document", as in
Code:
/usr/sbin/sendmail user@host << EOM
From: Colucix
To: user@host
Subject: Test
$(date)
$(echo "DEV - There are $RETURN_CODE errors in Alert log)
$(any_other_command)
Some text here.
Bye
EOM
The first part of the input to sendmail is to fill the various fields of the e-mail, the rest goes into the mail body.
Thanks Colucix, thats worked fine.. sorry to bother you again.can u please tell me how to add date with the current time to the subject
such that it should display the subject test with time
(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log").
am executing the script with sh in the line it sends mail to the user
where as when I add it to the cron .. it does'nt work .. any idea colucix ?..How I can fix it ?
user is added to cron.allow and no users are in cron.deny
cornd is runniing..
Thanks Colucix, thats worked fine.. sorry to bother you again.can u please tell me how to add date with the current time to the subject such that it should display the subject test with time
You're welcome! And don't worry, you don't bother me. You can add date to the subject in the same way you use command substitution in the mail body, e.g.
Code:
Subject: $(date +%d-%b-%Y) - any other text here
The idea is: you're running the sendmail command from a shell, and as for any other command the shell expands variables, does command substitutions and so on... before actually executing the given commands. In this way you can put any shell variable, or any command substitution inside the "here document" which represents the mail to be sent: the shell takes care of building the text and pass it as input to sendmail. For an explanation of "here documents" you can see Chapter 18 of the Advanced Bash Scripting Guide.
Regarding your other issue about the cron job, I'm following the other thread of yours and... it's puzzling me! Bye.
Thanks Colucix, thats worked fine.. sorry to bother you again.can u please tell me how to add date with the current time to the subject
such that it should display the subject test with time
(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log").
am executing the script with sh in the line it sends mail to the user
where as when I add it to the cron .. it does'nt work .. any idea colucix ?..How I can fix it ?
user is added to cron.allow and no users are in cron.deny
cornd is runniing..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.