#!/usr/bin/perl -w use strict; use Getopt::Long; my $sudo = ''; $sudo = "sudo " if ($> != 0); my $worksheet = 0; my $brief = 0; my $standardin = 0; my $help = 0; GetOptions('worksheet' => \$worksheet, 'brief' => \$brief, 'stdin' => \$standardin, 'help' => \$help); if ($help) { print "--worksheet, -w Display in sections appropriate for insertion\n", " into SSO_Worksheet.xls.\n", "--brief, -b Display in a single-line format, useful for\n", " comparing multiple hosts' configuration. (This\n", " is the default output format.)\n", "--stdin, -s Rather than calling scan directly, take input\n", " from stdin.\n", "--help, -h Display this help message.\n"; exit 0; } $brief = 1 if ($brief + $worksheet < 1); my $name = undef; my $serial = undef; my $type = undef; my %drives; my $bogus_serial = 0; my $line; foreach $line (($standardin) ? <> : qx{$sudo /usr/openv/volmgr/bin/goodies/scan}) { chomp($line); die if (defined($name) && defined($type) && defined($serial)); $name = (split('"', $line))[1] if ($line =~ m/^Device Name/); $serial = (split('"', $line))[1] if ($line =~ m/^Serial Number/); $type = (split(':', $line))[1] if ($line =~ m/^Device Type/); if (defined($type)) { if ($type =~ m/SDT_TAPE/) { if (! defined($serial) || length($serial) == 0) { $drives{$bogus_serial++} = $name } else { $drives{$serial} = $name } } $name = undef; $serial = undef; $type = undef; } } if ($brief) { foreach $serial (sort keys(%drives)) { printf "%20s %s\n", $drives{$serial}, $serial; } } if ($worksheet) { print "\n" if ($brief); print "Dev Paths by serial, column A (serial):\n" if ($worksheet); foreach $serial (sort keys(%drives)) { print "$serial\n"; } print "\nDev Paths by serial, column C (path):\n"; foreach $serial (sort keys(%drives)) { print "$drives{$serial}\n"; } }