The company where I work as a Unix system administrator, only uses the Korn shell, awk and sed. For technical reasons, I need to use Perl (5.005_03).
This script is to run on a server running Solaris, and will be used to scan for a point-in-time copy of a disk, import the volume manager disk group held on the disk, start the volumes and mount it on the corresponding mount points prior to a backup. The config file holds two columns, the first the volume name, the second the mount point. I am posting my code for review. I would appreciate any of you monks could give me advise/pointers on how I can improve the following code.
#!/usr/bin/perl ############################################################### # Variables ############################################################### $mountpointdata="/Backups/Config/mountpoint.config"; ############################################################### # Functions ############################################################### sub show_abort_banner{ print "\n\n\t\t\tAborting Import\n"; print "\t\t\t===============\n\n"; } ############################################################### # Main Script ############################################################### # Check if a scan required if ( $ARGV[0] =~ /-s/){ my $scan = 1; print "This script will search for specified disk groups\n"; shift; } print "\n\n\t\t Importing Disk Groups\n"; print "\t\t =====================\n\n"; while (<@ARGV>){ my $group = $_; # Check if the disk group is already imported $result=`vxdisk list | grep $group | wc -l | sed 's/ *//'`; if ($result > 0){ # Display Abort Banner show_abort_banner; print "\tThe disk group $group is already imported\n\n"; die; } if($scan){ print "\n\nActivating the $group session\n\n"; # Scan for a snapshot for the specified group system ("/usr/admsnap/admsnap activate -s $group > /dev/null 2>&1 +"); if ($?){ # Work out return code my $rc = $? >> 8; # Display Abort Banner show_abort_banner; # No new snapshots if ($rc == 11){ print "\tUnable to activate the snapshot: $group \n"; print "\tNo devices matching this session name were found\n\n +"; die; } else { print "\tFailed with untrapped error: $rc\n\n"; die; } } } print "\n\nImporting the Volume Manager disk group: $group\n"; system ("vxdctl enable"); system ("vxdg import $group > /dev/null 2>&1"); if ($?){ # Work out return code my $rc = $? >> 8; # Display Abort Banner show_abort_banner; # No disks found if ( $rc == 20 ){ print "\tUnable to import the disk group as there were\n"; print "\tNo valid disk(s) found containing disk group !!\n\n"; die; } } # Start the volumes system ("vxvol -g $group startall"); if ($?){ print "\n\n\t\t\tAborting Import\n"; print "\t\t\t===============\n\n"; print "\tCould not start the volumes in disk group $group\n\n"; die; } # Check if the mountpoint.config file is still there if ( ! -e "$mountpoint.config"){ # Display Abort Banner show_abort_banner; print "\tCould not find the mountpoint.config file\n\n"; die; } print "Mount the File Systems\n"; open MPCFG,"<$mountpointdata"; while ( defined ( my $line = <MPCFG>)){ if ( $line =~ /$group/ ){ ( $volume,$mountpoint ) = split /\s+/,$line; system ("mount -F ufs $volume $mountpoint"); if ($?){ print "\n\n\t\t\tAborting Import\n"; print "\t\t\t===============\n\n"; print "\tCould not mount $volume on mountpoint\n\n"; die; } } } }
Thanks, Darren
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |