Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Inconsistent ls -l results??

by Anonymous Monk
on Jun 14, 2001 at 21:37 UTC ( #88524=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This may be more of a unix question than perl question, but here goes. I have two different programs that do the same thing,
$mod = `ls -l $db`;
In one program, I get for $mod:
-rw-r--r-- 1 hroberts 36761119 May 30 01:07 /usr/ncbi/blast/db/temp_ +big/patntdir/patnt.nsq
while in another I get:
-rw-r--r-- 1 hroberts staff 36761119 May 30 01:07 /usr/ncbi/blast +/db/temp_big/patntdir/patnt.nsq
Both programs are run as the same user. How in the world does one program get the field for group ownership (staff), and not the other??? This is on Solaris 2.6.

Comment on Inconsistent ls -l results??
Select or Download Code
Re: Inconsistent ls -l results??
by Beatnik (Parson) on Jun 14, 2001 at 21:49 UTC
    This might be more of a Perl answer than a UNIX one, but...

    Why not use Perls functionality to check file statistics?? stat is very good at that. Using shell calls for something like that is just plain silly, not to mention insecure.

    Update: ofcourse readdir and glob can be (ab)used for reading the directory's contents.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: Inconsistent ls -l results??
by premchai21 (Curate) on Jun 14, 2001 at 21:49 UTC
    Have you checked $db? Have you tested several times to see if something strange happened between runs?
(tye)Re: Inconsistent ls -l results??
by tye (Cardinal) on Jun 14, 2001 at 21:55 UTC

    Some versions of Unix require "ls -lg" to get the group owner of files listed. The solution? Use Perl's stat as already suggested.

            - tye (but my friends call me "Tye")
Re: Inconsistent ls -l results??
by ZZamboni (Curate) on Jun 14, 2001 at 22:19 UTC
    Solaris comes with two versions of ls: the BSD version in /usr/ucb/ls, and the SystemV version in /usr/bin/ls. And it turns out that the -g flag has opposite effects. On the BSD version, -g makes it show the group of the file (which is not shown by default), whereas in the System V version, the group is shown by default, and -g hides it.

    So the problem must be that your programs are using different paths, so they end up executing the different versions of ls.

    --ZZamboni

      That sounds good. I don't use stat because stat returns only epochal time, and I would have to import an extra module to re-parse that into human-comprehensible calendrical time.
        Not true. localtime($epoch_time) will return an array with all the time components. And scalar(localtime($epoch_time)) will even give you a nicely formatted string.

        --ZZamboni

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-12-22 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (114 votes), past polls