LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-03-2011, 06:02 AM   #1
linux_user2011
LQ Newbie
 
Registered: Apr 2011
Posts: 14

Rep: Reputation: 0
Redirecting output of 'sendmail -bv' to console


Hi,

I am using RHEL Linux 6.0

When I run 'sendmail -bv', it sends the mail delivery status report as a mail to the root. Is there a way I can redirect this to the console instead of sending as a mail.My requirement is to programatically find the mail host of the recipient for which I thought of using this 'sendmail -bv' command. Is there any other better way to find mail host of the recipient.

Regards,
 
Old 05-03-2011, 07:18 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Hi,

Are you sure about this. The command needs also the recipient, so it can produce some output
Quote:
sendmail -bv
Recipient names must be specified

sendmail -bv foo@gmail.com
foo@gmail.com... deliverable: mailer esmtp, host gmail.com., user foo@gmail.com
Maybe you're running postfix, or another mta, whose sendmail binary replacement is not a 100% compatible with sendmail

Regards
 
Old 05-04-2011, 12:28 AM   #3
linux_user2011
LQ Newbie
 
Registered: Apr 2011
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for the reply Bathory!

Now only I found that its postfix sendmail:
[root]# man sendmail
SENDMAIL(1) SENDMAIL(1)

NAME
sendmail - Postfix to Sendmail compatibility interface

And the command I am running is as below:
[root]# sendmail -bv abc@gmail.com
Mail Delivery Status Report will be mailed to <root>.


Is there a way I can redirect the above report to console. My requirement is to find the recipient's mail host programatically and I wanted to make my implementation simple by redirecting the sendmail's output to console and directly reading it from console. How do I do it?

Or is there any other better and simpler way to find out the recipient's mail host? Please advise...

Regards...
 
Old 05-04-2011, 02:37 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
IMO the output of the original sendmail -bv, is only useful for the mailer part. It allows you to see if the mail is local, if it's going through a relay, or directly via smtp and so on.
The host part says nothing useful. You can find the real smtp host(s) for a domain using dns tools, like dig:
Code:
dig mx gmail.com
<snip>
;; ANSWER SECTION:
gmail.com.              2205    IN      MX      5 gmail-smtp-in.l.google.com.
gmail.com.              2205    IN      MX      10 alt1.gmail-smtp-in.l.google.com.
gmail.com.              2205    IN      MX      20 alt2.gmail-smtp-in.l.google.com.
gmail.com.              2205    IN      MX      30 alt3.gmail-smtp-in.l.google.com.
gmail.com.              2205    IN      MX      40 alt4.gmail-smtp-in.l.google.com.
<snip>
 
Old 05-05-2011, 01:15 AM   #5
linux_user2011
LQ Newbie
 
Registered: Apr 2011
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks Bathory,

You said the host part says nothing useful. I just tried the below in my Solaris box:

bash-3.00# sendmail -bv abc@gmail.com
abc@gmail.com... deliverable: mailer esmtp, host gmail.com., user abc@gmail.com

bash-3.00# sendmail -bv abc@hotmail.com
abc@hotmail.com... deliverable: mailer esmtp, host hotmail.com., user abc@hotmai
l.com

bash-3.00# sendmail -bv abc@rediffmail.com
abc@rediffmail.com... deliverable: mailer esmtp, host rediffmail.com., user abc@
rediffmail.com


In all the above examples, the host part is same as the domain with an additional dot at the end. I was thinking that host represents the mail host or the relay host. Or is it just the domain name? Please correct me if I am wrong.

Regards
 
Old 05-05-2011, 03:06 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Quote:
I was thinking that host represents the mail host or the relay host.
It is supposed to be the host that will get the mail for that user.
In case you use a smarthost, the mailer part becomes relay and the host is the smarthost
Quote:
sendmail -bv foo@gmail.com
foo@gmail.com... deliverable: mailer relay, host smarthost.domain.com, user foo@gmail.com
Without a smarthost, sendmail uses the host part to do an MX lookup for it in order to find the actual smtp host to deliver the mail
You can take a look at chapter 5.0 of sendmail Cookbook by O'Reilly Media for details.

Regards
 
Old 05-05-2011, 11:27 PM   #7
linux_user2011
LQ Newbie
 
Registered: Apr 2011
Posts: 14

Original Poster
Rep: Reputation: 0
I need to get the equivalent of this host in RedHat Linux 6.0. But Linux 6.0 has postfix as its default mail server. I tried using postfix sendmail -bv but its output is different. How can I get the equivalent of host in RHEL Linux 6.0

Regards
 
Old 05-06-2011, 12:25 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Quote:
I need to get the equivalent of this host in RedHat Linux 6.0. But Linux 6.0 has postfix as its default mail server.
I was under the impression that RH still uses sendmail as the default mta, but after reading this, looks you're right. If you want, you can switch to sendmail running:
Code:
alternatives --config mta
Anyway you can filter root's mail (through procmail?) and extract the info you want.
 
Old 05-09-2011, 12:27 AM   #9
linux_user2011
LQ Newbie
 
Registered: Apr 2011
Posts: 14

Original Poster
Rep: Reputation: 0
I dont have sendmail installed in the box, hence I need to go with postfix sendmail.

Below is the output of sendmail (from Solaris box as I dont have a Linux 4/5 and this Solaris box has sendmail):

On Solaris:
-----------
bash-3.00# sendmail -bv pnet_register@bmc.compnet_register@bmc.com... deliverable: mailer esmtp, host bmc.com., user pnet_register@bmc.com

On Linux
----------
[root@vm-rlnx-rds1203 /]# sendmail -bv pnet_register@bmc.com
Mail Delivery Status Report will be mailed to <root>.
[root@vm-rlnx-rds1203 /]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/root": 8 messages 1 new
1 Mail Delivery System Thu May 5 11:52 62/2105 "Mail Delivery Status Report"
2 Mail Delivery System Thu May 5 11:54 62/2135 "Mail Delivery Status Report"
3 Mail Delivery System Thu May 5 11:57 62/2077 "Mail Delivery Status Report"
4 Mail Delivery System Mon May 9 10:32 62/2105 "Mail Delivery Status Report"
5 Mail Delivery System Mon May 9 10:32 62/2135 "Mail Delivery Status Report"
6 Mail Delivery System Mon May 9 10:45 62/2143 "Mail Delivery Status Report"
7 Mail Delivery System Mon May 9 10:51 62/2077 "Mail Delivery Status Report"
>N 8 Mail Delivery System Mon May 9 10:51 61/2066 "Mail Delivery Status Report"
& 8
Message 8:
From MAILER-DAEMON Mon May 9 10:51:50 2011
Return-Path: <>
X-Original-To: root@vm-rlnx-rds1203.bmc.com
Delivered-To: root@vm-rlnx-rds1203.bmc.com
Date: Mon, 9 May 2011 10:51:50 +0530 (IST)
From: MAILER-DAEMON@vm-rlnx-rds1203.bmc.com (Mail Delivery System)
Subject: Mail Delivery Status Report
To: root@vm-rlnx-rds1203.bmc.com
Auto-Submitted: auto-replied
Content-Type: multipart/report; report-type=delivery-status;
boundary="029AD162778.1304918510/vm-rlnx-rds1203.bmc.com"
Status: R

Part 1:
Content-Description: Notification
Content-Type: text/plain; charset=us-ascii

This is the mail system at host vm-rlnx-rds1203.bmc.com.

Enclosed is the mail delivery report that you requested.

The mail system

<pnet_register@bmc.com>: delivery via phx-flicker-01.bmc.com[172.24.33.152]:25:
250 2.1.5 Ok

Part 2:
Content-Description: Delivery report
Content-Type: message/delivery-status


Part 3:
Content-Description: Message Headers
Content-Type: text/rfc822-headers

Return-Path: <root@vm-rlnx-rds1203.bmc.com>
Received: by vm-rlnx-rds1203.bmc.com (Postfix, from userid 0)
id 029AD162778; Mon, 9 May 2011 10:51:48 +0530 (IST)
From: root@vm-rlnx-rds1203.bmc.com
Subject: probe
To: pnet_register@bmc.com
Message-Id: <20110509052149.029AD162778@vm-rlnx-rds1203.bmc.com>
Date: Mon, 9 May 2011 10:51:48 +0530 (IST)
&


The sendmail command returned the host as bmc.com. and the postfix output says delivery via phx-flicker-01.bmc.com I was wondering why both are different as I had given the same recipient. I couldnt find the exact equivalent of host from sendmail -bv output in postfis output

Regards
 
Old 05-09-2011, 02:17 AM   #10
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Hi,

Quote:
<pnet_register@bmc.com>: delivery via phx-flicker-01.bmc.com[172.24.33.152]:25:
250 2.1.5 Ok
Here is says that it's going to deliver the message through phx-flicker-01.bmc.com (I guess this is a relay host for your box). Most likely the sendmail in Solaris is not configured to use a smarthost (synonym of relayhost for postfix), otherwise it should also mention that (see also my post #6). You can test if you like, by adding in the DS line os sendmail.cf the relayhost, eg.
Code:
DSphx-flicker-01.bmc.com
and run sendmail -bv (do not restart sendmail, otherwise any mail sent during the test, will be forwarded to smarthost)

Also, if you take a look at the example here, you'll see that mail is delivered through mail.cloud9.net, which is the same as the output of dig mx"
Quote:
; <<>> DiG 9.7.3 <<>> mx postfix.org
<snio>
;; ANSWER SECTION:
postfix.org. 86388 IN MX 10 mail.cloud9.net.
<snip>
So once again, the original sendmail does not bother to show the actual MX of the domain. It just outputs the way the mail will be delivered.
 
Old 05-10-2011, 08:18 AM   #11
lrtward
Member
 
Registered: Feb 2011
Distribution: CentOS, Ubuntu
Posts: 97

Rep: Reputation: 9
Quote:
Originally Posted by linux_user2011 View Post

My requirement is to programatically find the mail host of the recipient for which I thought of using this 'sendmail -bv' command. Is there any other better way to find mail host of the recipient.
When you say "the mail host" do you mean the destination host where the mail accounts are housed, or the mail exchange host -- the one that accepts mail for a domain? It's probably going to be impossible to find the server name where the mail accounts are actually housed, but it should be pretty easy to find the MX hosts.

There can be multiple MX hosts:
Code:
]# dig mx hotmail.com

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> mx hotmail.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53333
;; flags: qr aa; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 24

;; QUESTION SECTION:
;hotmail.com.                   IN      MX

;; ANSWER SECTION:
hotmail.com.            3600    IN      MX      5 mx4.hotmail.com.
hotmail.com.            3600    IN      MX      5 mx1.hotmail.com.
hotmail.com.            3600    IN      MX      5 mx2.hotmail.com.
hotmail.com.            3600    IN      MX      5 mx3.hotmail.com.
You can get the list of all MX hosts by doing something like this:
Code:
dig mx domain.com | grep MX | awk '{ print $NF }' | grep -v MX
There are probably more elegant ways to do it but this should work.
 
Old 05-11-2011, 04:02 AM   #12
linux_user2011
LQ Newbie
 
Registered: Apr 2011
Posts: 14

Original Poster
Rep: Reputation: 0
I am actually modifying a script that works on Solaris to work on Linux. Below is the part of the script where we are getting mail host:

sendmail -bv pnet_register@bmc.com 2>&1 > /tmp/output
MAILHOST=`cat /tmp/output | grep "," | awk -F, '{print $2}' | awk '{print $2}'`

(here we get bmc.com. as the MAILHOST)

I think it is the one that accepts mail for a domain.

For converting it to work on linux, if I use the below command as suggested by you, I get the below output:

[root@vm-rlnx-rds1203 ~]# dig mx bmc.com | grep MX | awk '{ print $NF }' | grep -v MX
phx-flicker-01.bmc.com.
hou-flicker-01.bmc.com.

I wonder whether what I am doing is correct. If yes, they why on Solaris I am getting bmc.com. and on Linux phx-flicker-01.bmc.com. and
hou-flicker-01.bmc.com.

Regards
 
Old 05-11-2011, 04:59 AM   #13
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Hi,

As I've already told you, the original sendmail -bv, just outputs how the mail will be delivered (local, by relay, by smtp). It does not do a MX lookup to find the actual MX host of the recipient.The postfix sendmail -bv on the other side, simulates the whole delivery process, so it does the MX lookup and also connects to the MX host.
BTW, if you use dig in Solaris, you'll also get the same results for MX.

Regards
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Redirecting console output from a Qt application to a telnet session bameije Linux - Embedded & Single-board computer 4 01-21-2011 09:32 AM
redirecting physical console output pwalter Linux - Newbie 3 05-13-2009 07:18 AM
Redirecting output from screen to console from boot-up ? exceed1 Linux - General 3 11-23-2008 10:26 PM
A little help with redirecting output tybalt Linux - Newbie 1 08-04-2007 10:08 PM
Redirecting Console MadnessASAP Linux - Software 3 10-19-2005 12:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:02 PM.

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