Loading ...
Sorry, an error occurred while loading the content.

Need help with parsing output

Expand Messages
  • perl_1978
    I m trying to parse out the output from the following command the columns user, file size, date and file name and get rid of the Permission denied lines. I m
    Message 1 of 11 , Jan 19, 2006
    • 0 Attachment
      I'm trying to parse out the output from the following command the
      columns "user, file size, date and file name" and get rid of the
      Permission denied lines. I'm only familiar with a split when the data
      has a :, = or some kind of delimiter I can use to separate them but
      when it comes to white space I'm not sure how to do it. Any help would
      be appreciated.

      find /tmp -size +3000000c -mtime -5 | xargs ls -l

      ************** Output *******************

      find: /tmp/temp-file1: Permission denied
      find: /tmp/temp-file2: Permission denied
      -rw-r--r-- 1 user1 grp 7078871 Jan 18 13:59 /tmp/file1
      -rw-r--r-- 1 user2 grp 6904365 Jan 18 13:59 /tmp/file2
      -rw-r--r-- 1 user3 grp 6782813 Jan 18 13:59 /tmp/file3
      -rw-r--r-- 1 user4 grp 6791873 Jan 18 13:59 /tmp/file4
    • merlyn@stonehenge.com
      ... perl I m trying to parse out the output from the following command the perl columns user, file size, date and file name and get rid of the perl
      Message 2 of 11 , Jan 19, 2006
      • 0 Attachment
        >>>>> "perl" == perl 1978 <perl_1978@...> writes:

        perl> I'm trying to parse out the output from the following command the
        perl> columns "user, file size, date and file name" and get rid of the
        perl> Permission denied lines. I'm only familiar with a split when the data
        perl> has a :, = or some kind of delimiter I can use to separate them but
        perl> when it comes to white space I'm not sure how to do it. Any help would
        perl> be appreciated.

        Stop using "find". Do it directly within Perl, using the File::Find module.
        It'll likely be faster!

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • KalyanRaj
        Hi 1978, Split funtion actually splits the data by space( by default ). From the command you have mentioned , u can redirect the output to a file and using
        Message 3 of 11 , Jan 19, 2006
        • 0 Attachment
          Hi 1978,

          Split funtion actually splits the data by space( by default ).
          From the command you have mentioned , u can redirect the output to a file
          and using perl script you can easily trace out
          which files are Permission denied.

          Use the following guidelines to write a perl script to parse the output
          which is redirected to a file.

          1. read the file and
          2. split the data and find out for the keywords "Permission denied" . You
          can use regular expressions to do this.
          3. we can easily find out the name of the file which is denied. regex will
          do the stuff..

          Guide me if i'm wrong ...

          Regards,
          KalyanRaj

          -----Original Message-----
          From: perl-beginner@yahoogroups.com
          [mailto:perl-beginner@yahoogroups.com]On Behalf Of perl_1978
          Sent: Thursday, January 19, 2006 5:44 PM
          To: perl-beginner@yahoogroups.com
          Subject: [PBML] Need help with parsing output


          I'm trying to parse out the output from the following command the
          columns "user, file size, date and file name" and get rid of the
          Permission denied lines. I'm only familiar with a split when the data
          has a :, = or some kind of delimiter I can use to separate them but
          when it comes to white space I'm not sure how to do it. Any help would
          be appreciated.

          find /tmp -size +3000000c -mtime -5 | xargs ls -l

          ************** Output *******************

          find: /tmp/temp-file1: Permission denied
          find: /tmp/temp-file2: Permission denied
          -rw-r--r-- 1 user1 grp 7078871 Jan 18 13:59 /tmp/file1
          -rw-r--r-- 1 user2 grp 6904365 Jan 18 13:59 /tmp/file2
          -rw-r--r-- 1 user3 grp 6782813 Jan 18 13:59 /tmp/file3
          -rw-r--r-- 1 user4 grp 6791873 Jan 18 13:59 /tmp/file4





          Unsubscribing info is here:
          http://help.yahoo.com/help/us/groups/groups-32.html
          Yahoo! Groups Links
        • merlyn@stonehenge.com
          ... KalyanRaj Guide me if i m wrong ... wrong only in doing it all the hard way. And perl is about doing it easily. -- Randal L. Schwartz - Stonehenge
          Message 4 of 11 , Jan 19, 2006
          • 0 Attachment
            >>>>> "KalyanRaj" == KalyanRaj <kalyanrajs@...> writes:

            KalyanRaj> Guide me if i'm wrong ...

            "wrong" only in doing it all the hard way.

            And perl is about doing it easily.

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
            See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
          • acummingsus
            ... [ . . ] ... Perl is very strong at parsing variables. So, a file may not needed unless very huge data involved where memory becomes an issue. (and/or
            Message 5 of 11 , Jan 19, 2006
            • 0 Attachment
              --- In perl-beginner@yahoogroups.com, "KalyanRaj" <kalyanrajs@i...> wrote:
              [ . . ]
              > Use the following guidelines to write a perl script to parse the output
              > which is redirected to a file.

              Perl is very strong at parsing variables. So, a file may not needed
              unless very huge data involved where memory becomes an issue. (and/or
              possibly about the error stuff because Permission denied didn't assign
              to variable for me).

              Randal Schwartz will not steer you wrong. I advise you to follow the
              route which was offered to you by him.

              The scope of what's next is limited to my tinkerings (not an example,
              just tinkering so as for me to practice/learn). I share it so that
              others can see these particular expression ideas and in particular
              that a file may not needed.

              I couldn't get <== (my attempt at less than or equal to) to work. But
              == seems to work. Can anyone explain/share how to express less than
              or equal to given my $loop_tally situation that's enclosed below?

              #!/usr/bin/perl
              use strict;
              use warnings;
              use Cwd;

              my $ch_dir = '/';
              chdir( $ch_dir ) or die "Cant chdir to $ch_dir $!";
              print "\ncur_dir is:\n";
              print cwd, "\n\n";

              # not really all (the Perm denied fell not within this)
              my $all_orig_capture = `find /tmp -size +3000000c -mtime -5 | xargs ls
              -l`;

              print "orig_capture:\n";
              print $all_orig_capture, "\n\n";

              my @all_lines = split /\n/, $all_orig_capture;
              print $all_lines[1], "\n\n";
              print $all_lines[3], "\n\n";

              my $loop_tally = 1;
              foreach ( @all_lines ) {
              # print $_, "\n";
              my @line = split /\s+/, $_;
              $loop_tally ++;
              print "$line[5]\t$line[7]\n";
              last if $loop_tally == 8;
              } # end

              --
              Alan.
            • merlyn@stonehenge.com
              ... acummingsus # not really all (the Perm denied fell not within this) acummingsus my $all_orig_capture = `find /tmp -size +3000000c -mtime -5 | xargs ls
              Message 6 of 11 , Jan 19, 2006
              • 0 Attachment
                >>>>> "acummingsus" == acummingsus <acelists@...> writes:

                acummingsus> # not really all (the Perm denied fell not within this)
                acummingsus> my $all_orig_capture = `find /tmp -size +3000000c -mtime -5 | xargs ls
                acummingsus> -l`;

                Even if you don't understand File::Find, there's always my File::Finder
                wrapper (in the CPAN) that is almost a literal translation of find(1)
                commands.

                use File::Finder; # from the CPAN
                my @big_new_files = File::Finder->size('+3000000c')->mtime('-5')->in('/tmp');

                There. There's your files. And it looks a lot like find(1). And you don't
                have to parse the output of find. And it's probably faster.

                --
                Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
              • Shawn Corey
                ... Other things you might want to look up: perldoc File::Stat perldoc -f getgrgid perldoc -f getpwuid perldoc POSIX (and search for strftime ) -- Just my
                Message 7 of 11 , Jan 21, 2006
                • 0 Attachment
                  merlyn@... wrote:
                  > Stop using "find". Do it directly within Perl, using the File::Find module.
                  > It'll likely be faster!

                  Other things you might want to look up:

                  perldoc File::Stat
                  perldoc -f getgrgid
                  perldoc -f getpwuid
                  perldoc POSIX (and search for 'strftime')


                  --

                  Just my 0.00000002 million dollars worth,
                  --- Shawn

                  "Probability is now one. Any problems that are left are your own."
                  SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

                  * Perl tutorials at http://perlmonks.org/?node=Tutorials
                  * A searchable perldoc is available at http://perldoc.perl.org/
                • perl_1978
                  Thanks merlyn I will try that Find module it looks interesting. ... this) ... mtime -5 | xargs ls ... File::Finder ... (1) ... you don t ... 777 0095 ... Perl
                  Message 8 of 11 , Jan 26, 2006
                  • 0 Attachment
                    Thanks merlyn I will try that Find module it looks interesting.

                    --- In perl-beginner@yahoogroups.com, merlyn@s... wrote:
                    >
                    > >>>>> "acummingsus" == acummingsus <acelists@g...> writes:
                    >
                    > acummingsus> # not really all (the Perm denied fell not within
                    this)
                    > acummingsus> my $all_orig_capture = `find /tmp -size +3000000c -
                    mtime -5 | xargs ls
                    > acummingsus> -l`;
                    >
                    > Even if you don't understand File::Find, there's always my
                    File::Finder
                    > wrapper (in the CPAN) that is almost a literal translation of find
                    (1)
                    > commands.
                    >
                    > use File::Finder; # from the CPAN
                    > my @big_new_files = File::Finder->size('+3000000c')->mtime('-5')-
                    >in('/tmp');
                    >
                    > There. There's your files. And it looks a lot like find(1). And
                    you don't
                    > have to parse the output of find. And it's probably faster.
                    >
                    > --
                    > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
                    777 0095
                    > <merlyn@s...> <URL:http://www.stonehenge.com/merlyn/>
                    > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                    > See PerlTraining.Stonehenge.com for onsite and open-enrollment
                    Perl training!
                    >
                  • perl_1978
                    Thanks merlyn I will try that Find module it looks interesting. ... this) ... mtime -5 | xargs ls ... File::Finder ... (1) ... you don t ... 777 0095 ... Perl
                    Message 9 of 11 , Jan 26, 2006
                    • 0 Attachment
                      Thanks merlyn I will try that Find module it looks interesting.

                      --- In perl-beginner@yahoogroups.com, merlyn@s... wrote:
                      >
                      > >>>>> "acummingsus" == acummingsus <acelists@g...> writes:
                      >
                      > acummingsus> # not really all (the Perm denied fell not within
                      this)
                      > acummingsus> my $all_orig_capture = `find /tmp -size +3000000c -
                      mtime -5 | xargs ls
                      > acummingsus> -l`;
                      >
                      > Even if you don't understand File::Find, there's always my
                      File::Finder
                      > wrapper (in the CPAN) that is almost a literal translation of find
                      (1)
                      > commands.
                      >
                      > use File::Finder; # from the CPAN
                      > my @big_new_files = File::Finder->size('+3000000c')->mtime('-5')-
                      >in('/tmp');
                      >
                      > There. There's your files. And it looks a lot like find(1). And
                      you don't
                      > have to parse the output of find. And it's probably faster.
                      >
                      > --
                      > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
                      777 0095
                      > <merlyn@s...> <URL:http://www.stonehenge.com/merlyn/>
                      > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                      > See PerlTraining.Stonehenge.com for onsite and open-enrollment
                      Perl training!
                      >
                    • perl_1978
                      I also forgot to mention I need to do this across 300+ servers so how do you get around installing the File::Finder module on all servers? So that is why I m
                      Message 10 of 11 , Jan 26, 2006
                      • 0 Attachment
                        I also forgot to mention I need to do this across 300+ servers so
                        how do you get around installing the File::Finder module on all
                        servers? So that is why I'm using the Unix find command in my code.


                        --- In perl-beginner@yahoogroups.com, merlyn@s... wrote:
                        >
                        > >>>>> "acummingsus" == acummingsus <acelists@g...> writes:
                        >
                        > acummingsus> # not really all (the Perm denied fell not within
                        this)
                        > acummingsus> my $all_orig_capture = `find /tmp -size +3000000c -
                        mtime -5 | xargs ls
                        > acummingsus> -l`;
                        >
                        > Even if you don't understand File::Find, there's always my
                        File::Finder
                        > wrapper (in the CPAN) that is almost a literal translation of find
                        (1)
                        > commands.
                        >
                        > use File::Finder; # from the CPAN
                        > my @big_new_files = File::Finder->size('+3000000c')->mtime('-5')-
                        >in('/tmp');
                        >
                        > There. There's your files. And it looks a lot like find(1). And
                        you don't
                        > have to parse the output of find. And it's probably faster.
                        >
                        > --
                        > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
                        777 0095
                        > <merlyn@s...> <URL:http://www.stonehenge.com/merlyn/>
                        > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                        > See PerlTraining.Stonehenge.com for onsite and open-enrollment
                        Perl training!
                        >
                      • merlyn@stonehenge.com
                        ... perl I also forgot to mention I need to do this across 300+ servers so perl how do you get around installing the File::Finder module on all perl
                        Message 11 of 11 , Jan 26, 2006
                        • 0 Attachment
                          >>>>> "perl" == perl 1978 <perl_1978@...> writes:

                          perl> I also forgot to mention I need to do this across 300+ servers so
                          perl> how do you get around installing the File::Finder module on all
                          perl> servers? So that is why I'm using the Unix find command in my code.

                          You can include the two .pm files that make up File::Finder directly
                          in your source code. Just do this in your file:

                          BEGIN {
                          ... contents of File::Finder::Steps here, up to the __END__
                          }

                          BEGIN {
                          ... contents of File::Finder here, up to the __END__
                          }

                          and then the rest of your code. You might also have to mess with %INC... I
                          can't remember.

                          Or look into PAR (in the CPAN), which will create an executable for a specific
                          architecture if your machines are all similar.

                          --
                          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                          Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                          See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
                        Your message has been successfully submitted and would be delivered to recipients shortly.