Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

PATH/tr/basename mystery

by myuserid7 (Scribe)
on Apr 14, 2005 at 11:50 UTC ( [id://447714]=perlquestion: print w/replies, xml ) Need Help??

myuserid7 has asked for the wisdom of the Perl Monks concerning the following question:

I have a troublesome script which is causing some grief. I've simplified it to a few lines, but the output is confusing me. It seems that tr or basename are being called somewhere without paths.

The script fails on Debian 3.0, but works on Fedora.
Here it is:
#!/usr/bin/perl -w use strict; $ENV{'PATH'}=''; # removing this line makes it work open (MAILQ, "/usr/bin/mailq |") or die "open failed: $!\n";
And here is the error:
/usr/bin/mailq: basename: No such file or directory /usr/bin/mailq: tr: No such file or directory

Updated Steve_p - changed pre tags to code tags

Replies are listed 'Best First'.
Re: PATH/tr/basename mystery
by Roy Johnson (Monsignor) on Apr 14, 2005 at 11:54 UTC
    Looks like mailq is a script or includes system calls. Have you taken a look at it?

    Caution: Contents may have been coded under pressure.
      You're excellent! I had assumed mailq was a compiled binary. It's a shell script, with paths omitted for the tr and basename commands.
      Thanks a lot :)
Re: PATH/tr/basename mystery
by gellyfish (Monsignor) on Apr 14, 2005 at 12:03 UTC

    To add a bit to the other replies, where your local MTA is sendmail then the mailq command is essentially an alias to sendmail -bp and so emptying $PATH shouldn't cause a problem, however some other MTAs operate differently and only provide the mailq command for compatibility with sendmail - in these places it is likely that mailq is a shell script (as you have seen), your best bet is not to set the $ENV{PATH} to '' but to set it to some (relatively) safe valuee such as '/bin:/usr/bin'. Alternatively you could edit the mailq script to provide the full path for the commands it can't find.

    /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://447714]
Approved by tlm
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found