LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 12-02-2007, 06:43 AM   #1
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Rep: Reputation: 30
sendmail subject configuration


Hai all,

I've configured sendmail in my Linux machine and it is working fine and am sending mail like :


echo "Test" | sendmail -v oracle@ora.com.su

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.

Please guide
Yusuf
 
Old 12-02-2007, 07:06 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
'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".
 
Old 12-03-2007, 01:20 AM   #3
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Original Poster
Rep: Reputation: 30
unspawn

Quote:
Originally Posted by unSpawn View Post
'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" | /usr/sbin/sendmail -t user@host'


it works fine.. where I can add the message of the mail. please guide

Yusuf
 
Old 12-03-2007, 10:27 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
'(echo "Subject: Test"; echo; cat /etc/hosts) | /usr/sbin/sendmail -t user@host'
 
Old 12-04-2007, 06:34 AM   #5
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by unSpawn View Post
'(echo "Subject: Test"; echo; cat /etc/hosts) | /usr/sbin/sendmail -t user@host'


Thanks unspawn for your answer, I did the following as u said :


oracrp@oracle test]$ cat alert.sh
#!/bin/sh
# Script used to monitor the database alert log file
RETURN_CODE=`grep ORA-* /d02/oracle/oracrp/proddb/9.2.0/admin/DEV_oracle/bdump/alert_DEV.log | wc -l`
if [ $RETURN_CODE -eq 0 ]
then
exit 0
else
'(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log)' | /usr/sbin/sendmail erp_webmail@ali.com.kw

exit 1
fi



am getting the error :

alert.sh: line 8: (echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log): command not found

Guide please

Yusuf
 
Old 12-04-2007, 08:20 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
(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.
 
Old 12-04-2007, 03:29 PM   #7
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by colucix View Post
Code:
(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 for your patience and guidance
Yusuf
 
Old 12-05-2007, 03:46 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by yusufs View Post
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.
 
Old 12-06-2007, 03:29 AM   #9
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by yusufs View Post
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 for your patience and guidance
Yusuf
Thanks Colucix.. that helped me out.


Yusuf
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Forward subject in sendmail w3bd3vil Linux - General 1 02-06-2007 07:53 AM
Forward subject in sendmail w3bd3vil Linux - General 0 02-06-2007 07:31 AM
sendmail subject via script ryedunn Linux - Newbie 3 01-08-2005 12:11 PM
subject parameter for sendmail? pwtct Linux - Software 4 08-06-2004 10:58 AM
sendmail (dont just ignore it 'cause its got sendmail in the subject :P) GnomeKing Linux - Networking 1 11-12-2001 09:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration