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

Re: [PBML] More efficient script

Expand Messages
  • Paul.G
    Hi I have written a script that does what I want, but it looks rather messy. Would be interested if any one could indicate how I could make it more efficient.
    Message 1 of 11 , Apr 3, 2012
    • 0 Attachment
      Hi


      I have written a script that does what I want, but it looks rather messy. Would be interested if any one could indicate how I could make it more efficient. The perl script and output is below.


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

      my @result;
      my $result;
      my $PV;
      my @PV;
      my $junk1;
      my $junk2;
      my $junk3;
      my $AllocatedPE;

      open(CMD,"/usr/sbin/vgdisplay -v vg03 | /usr/bin/grep 'PV Name'|");
      undef($/);
      $result = <CMD>;

      @result = split(/\n/,$result);

      foreach $result (@result) {
                my ($junk1, $junk2, $junk3, $PV) = split(/\s+/, $result);
                print "$PV   \n";
                push @PV, $PV;
      }

      foreach $PV (@PV) {
             open(CMD,"/usr/sbin/pvdisplay $PV | grep 'Allocated PE|");
             ($junk1, $junk2, $AllocatedPE) = split(/\s+/, <CMD>);
             if ($AllocatedPE == 0) {
                 print "Unallocated PV with free extents is $PV \n";
             }
      }

       
      Result:
       
      /dev/disk/disk46  
      /dev/disk/disk48  
      /dev/disk/disk47  
      Unallocated PV with free extents is /dev/disk/disk48 


      cheers

      Paul



      ________________________________

      Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html

      Switch to: Text-Only, Daily Digest • Unsubscribe • Terms of Use
      .



      [Non-text portions of this message have been removed]
    • Shawn H Corey
      ... Unused items should be undef: my (undef, undef, undef, $PV) = split(/ s+/, $result); You could alternately use an index: my $PV = (split(/ s+/,
      Message 2 of 11 , Apr 3, 2012
      • 0 Attachment
        On 12-04-03 09:18 AM, Paul.G wrote:
        > my ($junk1, $junk2, $junk3, $PV) = split(/\s+/, $result);

        Unused items should be undef:

        my (undef, undef, undef, $PV) = split(/\s+/, $result);

        You could alternately use an index:

        my $PV = (split(/\s+/, $result))[3];


        --
        Just my 0.00000002 million dollars worth,
        Shawn

        Programming is as much about organization and communication
        as it is about coding.

        [updated for today's programmers]
        "Show me your code and conceal your interfaces, and I shall continue
        to be mystified. Show me your interfaces, and I won't usually need
        your code; it'll be obvious."
        -- Fred Brooks

        Don't be clever; being great is good enough.
      • merlyn@stonehenge.com
        ... Paul open(CMD, /usr/sbin/vgdisplay -v vg03 | /usr/bin/grep PV Name | ); Paul undef($/); Paul $result = ; Paul @result = split(/ n/,$result); my
        Message 3 of 11 , Apr 3, 2012
        • 0 Attachment
          >>>>> "Paul" == Paul G <medura43@...> writes:

          Paul> open(CMD,"/usr/sbin/vgdisplay -v vg03 | /usr/bin/grep 'PV Name'|");
          Paul> undef($/);
          Paul> $result = <CMD>;

          Paul> @result = split(/\n/,$result);

          my @result = grep /PV Name/, `/usr/sbin/vdisplay -v vg03`;


          Paul> foreach $result (@result) {
          Paul>           my ($junk1, $junk2, $junk3, $PV) = split(/\s+/, $result);
          Paul>           print "$PV   \n";
          Paul>           push @PV, $PV;
          Paul> }

          What Shawn said.

          Paul> foreach $PV (@PV) {
          Paul>        open(CMD,"/usr/sbin/pvdisplay $PV | grep 'Allocated PE|");
          Paul>        ($junk1, $junk2, $AllocatedPE) = split(/\s+/, <CMD>);
          Paul>        if ($AllocatedPE == 0) {
          Paul>            print "Unallocated PV with free extents is $PV \n";
          Paul>        }
          Paul> }

          What we both said. :)

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          See http://methodsandmessages.posterous.com/ for Smalltalk discussion
        • Matthew K
          DISCLAIMER: I don t have vgdisplay, so I can t really test this to see if it works, but it might be a little simpler to start with something closer to this.
          Message 4 of 11 , Apr 3, 2012
          • 0 Attachment
            DISCLAIMER: I don't have vgdisplay, so I can't really test this to see if it works, but it might be a little simpler to start with something closer to this.

            while (`/usr/sbin/vgdisplay
            -v vg03 | /usr/bin/grep 'PV Name| awk '{print
            $4}'`) {
                 
            next if  $_ !~ /^\//;
                  print "Unallocated
            PV with free extents is $_ \n" unless ( `/usr/sbin/pvdisplay
            $PV | grep 'Allocated PE|awk '{print $3}'`);
            }



            >________________________________
            > From: Paul.G <medura43@...>
            >To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
            >Sent: Tuesday, April 3, 2012 7:18 AM
            >Subject: Re: [PBML] More efficient script
            >
            >

            >Hi
            >
            >I have written a script that does what I want, but it looks rather messy. Would be interested if any one could indicate how I could make it more efficient. The perl script and output is below.
            >
            >#!/usr/bin/perl
            >use strict;
            >use warnings;
            >
            >my @result;
            >my $result;
            >my $PV;
            >my @PV;
            >my $junk1;
            >my $junk2;
            >my $junk3;
            >my $AllocatedPE;
            >
            >open(CMD,"/usr/sbin/vgdisplay -v vg03 | /usr/bin/grep 'PV Name'|");
            >undef($/);
            >$result = <CMD>;
            >
            >@result = split(/\n/,$result);
            >
            >foreach $result (@result) {
            >          my ($junk1, $junk2, $junk3, $PV) = split(/\s+/, $result);
            >          print "$PV   \n";
            >          push @PV, $PV;
            >}
            >
            >foreach $PV (@PV) {
            >       open(CMD,"/usr/sbin/pvdisplay $PV | grep 'Allocated PE|");
            >       ($junk1, $junk2, $AllocatedPE) = split(/\s+/, <CMD>);
            >       if ($AllocatedPE == 0) {
            >           print "Unallocated PV with free extents is $PV \n";
            >       }
            >}
            >

            >Result:

            >/dev/disk/disk46  
            >/dev/disk/disk48  
            >/dev/disk/disk47  
            >Unallocated PV with free extents is /dev/disk/disk48 
            >
            >cheers
            >
            >Paul
            >
            >________________________________
            >
            >Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
            >
            >Switch to: Text-Only, Daily Digest • Unsubscribe • Terms of Use
            >.
            >
            >[Non-text portions of this message have been removed]
            >
            >
            >
            >
            >

            [Non-text portions of this message have been removed]
          • merlyn@stonehenge.com
            ... Matthew while (`/usr/sbin/vgdisplay Matthew -v vg03 | /usr/bin/grep PV Name| awk {print Matthew $4} `) { Matthew       Matthew next if  $_ !~
            Message 5 of 11 , Apr 3, 2012
            • 0 Attachment
              >>>>> "Matthew" == Matthew K <matt_hew@...> writes:

              Matthew> while (`/usr/sbin/vgdisplay
              Matthew> -v vg03 | /usr/bin/grep 'PV Name| awk '{print
              Matthew> $4}'`) {
              Matthew>      
              Matthew> next if  $_ !~ /^\//;
              Matthew>       print "Unallocated
              Matthew> PV with free extents is $_ \n" unless ( `/usr/sbin/pvdisplay
              Matthew> $PV | grep 'Allocated PE|awk '{print $3}'`);
              Matthew> }

              Oh, hell no. perl, grep, awk, shell! Seriously. :(

              Also, my public announcement that must be repeated from time to time,
              as made evidenced above.

              **************************************************
              *
              * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
              *
              * The official one is at beginners@..., with instructions on how to
              * join at http://lists.perl.org/list/beginners.html.
              *
              * You'll get far better response there, not to say you won't get *any* here.
              *
              **************************************************


              --
              Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
              See http://methodsandmessages.posterous.com/ for Smalltalk discussion
            • Tim Lewis
              Please forgive the hijack Randall. Will you be at the Perl conference in Madison? [Non-text portions of this message have been removed]
              Message 6 of 11 , Apr 3, 2012
              • 0 Attachment
                Please forgive the hijack Randall. Will you be at the Perl conference in Madison?



                [Non-text portions of this message have been removed]
              • Randal L. Schwartz
                YAPC? Yes, I m doing a two hour git tutorial. Sent from my iPhone, so blame it for any speeling misteaks.
                Message 7 of 11 , Apr 3, 2012
                • 0 Attachment
                  YAPC? Yes, I'm doing a two hour git tutorial.

                  Sent from my iPhone, so blame it for any speeling misteaks.

                  On Apr 3, 2012, at 12:20 PM, "Tim Lewis" <twlewis@...> wrote:

                  > Please forgive the hijack Randall. Will you be at the Perl conference in Madison?
                  >
                  >
                  >
                  > [Non-text portions of this message have been removed]
                  >
                  >
                  >
                  > ------------------------------------
                  >
                  > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links
                  >
                  >
                  >
                • Paul.G
                  Thanks again for everyone s input, much appreciated. ________________________________ From: Shawn H Corey To:
                  Message 8 of 11 , Apr 6, 2012
                  • 0 Attachment
                    Thanks again for everyone's input, much appreciated.



                    ________________________________
                    From: Shawn H Corey <shawnhcorey@...>
                    To: perl-beginner@yahoogroups.com
                    Sent: Tuesday, 3 April 2012 11:30 PM
                    Subject: Re: [PBML] More efficient script


                     
                    On 12-04-03 09:18 AM, Paul.G wrote:
                    > my ($junk1, $junk2, $junk3, $PV) = split(/\s+/, $result);

                    Unused items should be undef:

                    my (undef, undef, undef, $PV) = split(/\s+/, $result);

                    You could alternately use an index:

                    my $PV = (split(/\s+/, $result))[3];

                    --
                    Just my 0.00000002 million dollars worth,
                    Shawn

                    Programming is as much about organization and communication
                    as it is about coding.

                    [updated for today's programmers]
                    "Show me your code and conceal your interfaces, and I shall continue
                    to be mystified. Show me your interfaces, and I won't usually need
                    your code; it'll be obvious."
                    -- Fred Brooks

                    Don't be clever; being great is good enough.



                    [Non-text portions of this message have been removed]
                  Your message has been successfully submitted and would be delivered to recipients shortly.