Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to get the sendmail path
Hi

I wrote a program using send mail for a mail application. In the server I wa
s 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. Pleas
e tell me the correct way to do it.

Thanks
Anish


Report this thread to moderator Post Follow-up to this message
Old Post
Anish Kumar K
06-04-05 08:57 AM


Re: How to get the sendmail path
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
>


Report this thread to moderator Post Follow-up to this message
Old Post
Anish Kumar K
06-04-05 08:57 AM


Re: How to get the sendmail path
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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
06-04-05 08:57 AM


Re: How to get the sendmail path
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

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
06-04-05 08:57 AM


Re: How to get the sendmail path
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 anothe
r
way.

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


joe

> ----- 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
> 

Report this thread to moderator Post Follow-up to this message
Old Post
John Doe
06-04-05 01:55 PM


Re: How to get the sendmail path
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

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
06-04-05 08:55 PM


Re: How to get the sendmail path
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

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
06-04-05 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:45 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.