For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2005 > How to get the sendmail path









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to get the sendmail path
Anish Kumar K

2005-06-04, 3:57 am

Hi

I wrote a program using send mail for a mail application. In the server I was testing it sendmail was installed in /usr/bin/sendmail.

But in a different server the path is different. Isn;t there a easy way for this. Like I need to get the path of the send mail and then assign it. Please tell me the correct way to do it.

Thanks
Anish

Anish Kumar K

2005-06-04, 3:57 am

yeah this isfine. But In the Program I have given like

my $sendmailPath=PATH WHERE IT IS INSTALLED.

In the perl program itself I need to finfd it out

As I don;t want to do it everytime I change it to a new server...

Anish

----- Original Message -----
From: "Chris Devers" <cdevers@pobox.com>
To: "Anish Kumar K" <anish@vitalect-india.com>
Cc: "Perl Beginners List" <beginners@perl.org>
Sent: Saturday, June 04, 2005 10:39 AM
Subject: Re: How to get the sendmail path


> On Sat, 4 Jun 2005, Anish Kumar K wrote:
>
>
> If you're on a Unix-ish platform, and the sendmail program is installed
> somewhere in your $PATH, the `which` command can help. For instance:
>
> $ which sendmail
> /usr/sbin/sendmail
> $
>
> This is on OSX. It can be other places on other platforms.
>
> If it isn't in your $PATH, then the `locate` command may help. Chances
> are, it's going to be in a directory no deeper than three or four levels
> down, so we can use `grep -v` to exclude deeper paths:
>
> $ locate sendmail | grep -v '/.*/.*/.*/.*/'
> /Users/cdevers/bin/update_sendmail
> /usr/sbin/sendmail
> $
>
> This turns it up again, along with a false hit in my home directory.
> Chances are you'll get similiar false hits, but hopefully the real one
> will be clear enough.
>
> If you don't have the `locate` database on your system, you're going to
> have to walk the while filesystem, using something like `find`. Here's
> one way to do it, but it will be very, very, very slow:
>
> $ find / -type f | grep -v '/.*/.*/.*/.*/'
>
> The output from this should be similar to what `locate` would have; with
> luck you'll see it in a folder like /usr/lib, /usr/libexec, /usr/sbin,
> /usr/local/bin, /opt/bin, et cetera.
>
> Good luck!
>
>
> --
> Chris Devers
>


John W. Krahn

2005-06-04, 3:57 am

Chris Devers wrote:
>
> If you don't have the `locate` database on your system, you're going to
> have to walk the while filesystem, using something like `find`. Here's
> one way to do it, but it will be very, very, very slow:
>
> $ find / -type f | grep -v '/.*/.*/.*/.*/'

^^^^^^^^^^^^^^^^^^^^^^
Ick! Better to use the -maxdepth switch (if it is available.)

$ find / -type f -maxdepth 4



John
--
use Perl;
program
fulfillment
Chris Devers

2005-06-04, 3:57 am

On Sat, 4 Jun 2005, Anish Kumar K wrote:

> Isn't there a easy way [to find sendmail] [question-mark]


If you're on a Unix-ish platform, and the sendmail program is installed
somewhere in your $PATH, the `which` command can help. For instance:

$ which sendmail
/usr/sbin/sendmail
$

This is on OSX. It can be other places on other platforms.

If it isn't in your $PATH, then the `locate` command may help. Chances
are, it's going to be in a directory no deeper than three or four levels
down, so we can use `grep -v` to exclude deeper paths:

$ locate sendmail | grep -v '/.*/.*/.*/.*/'
/Users/cdevers/bin/update_sendmail
/usr/sbin/sendmail
$

This turns it up again, along with a false hit in my home directory.
Chances are you'll get similiar false hits, but hopefully the real one
will be clear enough.

If you don't have the `locate` database on your system, you're going to
have to walk the while filesystem, using something like `find`. Here's
one way to do it, but it will be very, very, very slow:

$ find / -type f | grep -v '/.*/.*/.*/.*/'

The output from this should be similar to what `locate` would have; with
luck you'll see it in a folder like /usr/lib, /usr/libexec, /usr/sbin,
/usr/local/bin, /opt/bin, et cetera.

Good luck!


--
Chris Devers
John Doe

2005-06-04, 8:55 am

Am Samstag, 4. Juni 2005 07.15 schrieb Anish Kumar K:
> yeah this isfine. But In the Program I have given like
>
> my $sendmailPath=PATH WHERE IT IS INSTALLED.
>
> In the perl program itself I need to finfd it out
>
> As I don;t want to do it everytime I change it to a new server...
>
> Anish


Hi

One way you could do it:

Set the $sendmailPath in a BEGIN block after detecting the OS the program is
running on. Something like

BEGIN {
our $sendmail;
if ($^O eq 'linux') {
$sendmail='/usr/sbin/sendmail';
}
elsif ($^O eq ....) {
....
}
}

if there are more than one possibility on a single plattform, you could
additionaly use file test operators to find out if a certain file is present
and executable.


The use of a configfile with the path to the sendmail binary would be another
way.

Eventually you want to check one of the Mail modules on search.cpan.org.


joe
[color=darkred]
> ----- Original Message -----
> From: "Chris Devers" <cdevers@pobox.com>
> To: "Anish Kumar K" <anish@vitalect-india.com>
> Cc: "Perl Beginners List" <beginners@perl.org>
> Sent: Saturday, June 04, 2005 10:39 AM
> Subject: Re: How to get the sendmail path
>
Chris Devers

2005-06-04, 3:55 pm

On Fri, 3 Jun 2005, John W. Krahn wrote:

> Chris Devers wrote:
> ^^^^^^^^^^^^^^^^^^^^^^
> Ick! Better to use the -maxdepth switch (if it is available.)
>
> $ find / -type f -maxdepth 4


YMclearlyV :-)

This might be the "right" way to do this, but it has always rubbed me
the wrong way. The basic Unix commands are supposed to be simple things,
with each one doing one thing well. `find` *way* overreaches.

The `find` command has far too many options for me to feel comfortable
memorizing; it seems much easier to me to just use find to generate a
list of file, then hand off that list to another tool -- not least
because, as you suggest, different `find` versions may or may not have
all the esoteric little options, but basic things like `grep` should
pretty reliably be available almost anywhere sane -- which is to say,
anywhere other than Windows. :-)

I realize that I may be in the minority opinion on this. Oh well.


--
Chris Devers
Chris Devers

2005-06-04, 3:55 pm

On Sat, 4 Jun 2005, Anish Kumar K wrote:

> yeah this is fine. But In the Program I have given like
>
> my $sendmailPath=PATH WHERE IT IS INSTALLED.
>
> In the perl program itself I need to finfd it out
>
> As I don;t want to do it everytime I change it to a new server...


Ah.

Then clearly you need to be doing something more robust than this.

You *could* pull some clever code in your Perl to figure out where the
sendmail program lives, but it's hardly worth the effort. It can be all
over the place on different systems, and a lot of systems now won't have
it at all, or it won't be configured to work, etc.

You're *much* better off using one of the mail modules on CPAN, almost
all of which either already have tricks to figure out where `sendmail`
lives, or are written in such a way that they don't need it at all.



--
Chris Devers
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com