Hi Everyone,

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


In reply to First Unix Admin Script - Request for Constructive Critisism by D.Millin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.