|
NBU Scratch Script
I need to work on this...put functions in. #!/bin/perl
chomp ($date = `date`);
@protected = qw/Scratch NBDB_Duplicate/;
open(VMQUERYRN0, "vmquery -rn 0 | grep -v = |") or die "Cannot open a pipe from vmquery!";
open(VMQUERYRN1, "vmquery -rn 1 | grep -v = |") or die "Cannot open a pipe from vmquery!";
open(LOG, ">>/var/tmp/scratch.log") or die "Can't open LOGFILE!";
# Execute "vmquery -rn 0", and load the values into a hash of hashes.
while (defined($_ = )) {
if (/(.+):s+(.+)/) {
my $thing = $1;
my $value = $2;
$thing =~ s/s+/_/;
if (/media ID/) {$key = $value;};
if (/volume pool/) {$value =~ /(.+)s+(.+)/; $value = $1;};
$vm{$key}{$thing} = $value;
};
};
# Execute "vmquery -rn 1", and load the values into a hash of hashes.
while (defined($_ = )) {
if (/(.+):s+(.+)/) {
my $thing = $1;
my $value = $2;
$thing =~ s/s+/_/;
if (/media ID/) {$key = $value;};
if (/volume pool/) {$value =~ /(.+)s+(.+)/; $value = $1;};
$vm{$key}{$thing} = $value;
};
};
foreach my $tape ( keys %vm ) {
if ( ( $vm{$tape}{assigned} =~ /---/ ) && !( "@protected" =~ /$vm{$tape}{volume_pool}/ ) && !( $tape =~ /CLN/ ) )
{
`vmchange -M yang -h yang -p 3 -m $tape`;
print LOG "$date: $tape added to scratch pool.\n";
};
};
|