Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use an array? 1

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
US
Code:
open VXDISK,"vxdisk -o alldgs list |" or die "unable to run vxdisk\n";

Using the above which works for the remainder of what I'm doing, however
I now need to make sure vxdisk doesn't read some disk groups, which
would work if I added
Code:
vxdisk -o alldgs list| grep -v rootdg | grep -v thisdg | grep -v thatdg |

But I cannot hard code the disk groups because this will run on different
servers with different groups that need to be excluded.

How can I disk groups to the line without hard coding? I can create a file
that contains the disk groups and open that file and add the contents to
an array like:
Code:
open(FILE,"dgfile");
while(<FILE>){
  chomp $_;
  push(@dg,"$_");
}

But how do I use it?
Code:
foreach my $diskgroup (@dg) {
  $vx = `vxdisk -o alldgs list | grep -v $diskgroup`

That isn't going to work.

Thanks.
 
I would just read the entire output of vxdisk list into an array and then use perl's own grep function to strip out the ones that you're not interested in (see perldoc -f grep).

Rather than doing that multiple times, once for each disk group, I'd just include them all in one regular expression, something like ^(rootdg|thisdg|thatdg)$.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top