Scripts – HDS Generate Horcm Entries

Print Friendly, PDF & Email
DISCLAIMER:

This script is as is. I give no warranty it will work as you expected on your system. You are running it at your own risk. If something goes wrong because of this script, I bear no responsibility.

Language:

perl

Platform:

server# cat /etc/release
                       Solaris 10 11/06 s10s_u3wos_10 SPARC
           Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
                        Use is subject to license terms.
                           Assembled 14 November 2006
server# perl -v
This is perl, v5.8.4 built for sun4-solaris-64int
(with 33 registered patches, see perl -V for more detail)

Purpose:

You have allocated a couple of hundred devices to primary and secondary servers from HDS arrrays. Now you want to add these devices into horcm files at each site and carry out truecopy operations on them. Supply the serial number of the arrays, name for device group, and individual/range of devices. It will display the output on the screen which you can copy/paste in horcm file under “HORCM_LDEV” section for individual server.

Trivia:

The device numbers given at command line must be hexadecimal (script will treat them as hexadecimal). 2 arguments to be provided (one per array), seperated by space. Each argument consists of serial number of array, name of consistency group, and list of devs allocated from that array. Seperate the devs with “-” if they are in range. Separate all devs by a comma. Example would be: 12AB-13AB,1123,5C6-5D7. Script doesn’t check whether 2 arguments are supplied. It sorts the device list on each array from lowest to highest device id, and starts pairing them up. This means device ids are paired up in their ascending order.

Usage:

Examples:


server# generate_horcm.pl 12345:TESTCG:1295-1299 67890:TESTCG:1195-1198,1194
List of devs for array ............ 12345
Constistency Group     ............ TESTCG
TESTCG TESTCG_1 12345 12:95
TESTCG TESTCG_2 12345 12:96
TESTCG TESTCG_3 12345 12:97
TESTCG TESTCG_4 12345 12:98
TESTCG TESTCG_5 12345 12:99

List of devs for array ............ 67890
Constistency Group     ............ TESTCG
TESTCG TESTCG_1 12345 11:94
TESTCG TESTCG_2 12345 11:95
TESTCG TESTCG_3 12345 11:96
TESTCG TESTCG_4 12345 11:97
TESTCG TESTCG_5 12345 11:98

server# 

Actual Script:


#!/usr/perl5/5.8.4/bin/perl

#################################################################################
# A script to generate the entries to add to hormc file
# Written by : Ketan Patel
#################################################################################

use strict;

my %mightyinfo;
my $entry;
my ($dev_temp,$devname,$firstdev,$lastdev,$firstdev_dec,$lastdev_dec,$devnum,$device,$ser,$cgname,
$devs,$count);
my @devsarray;

#=========================================================================================================
# Sub: usage - to show the help message
#=========================================================================================================
sub usage {
  print "usage:    ./generate_horcm.pl <serialnum>:<CGname>:<devnum>,<devnum>-<devnum> 
                   <serialnum>:<CGname>:<devnum>,<devnum>-<devnum>\n";
  print "example:  ./generate_horcm.pl 12345:DISKGROUP1:1743,2e44-2e4f 67890:DISKGROUP1:3441,46ae-46b2\n";
  print "\nNOTE:   Enter the device number without : in them (1234 instead of 12:34)\n";
  print "\nNOTE:   CGname should be same for both arrays to matchup with each other\n";
  print "\nNOTE:   Number of devices should be same for both the arrays. Script will still 
                   produce the output but horcm will not start.\n";
}
#==========================================================================================================

#MAIN BODY

my $leng = $#ARGV;

#If no arguments are provided, display the usage
if ( $leng eq -1 ) {
  usage;
}

#Process all arguments provided and save them in a hash
for my $i (0..$leng) {
  $entry = $ARGV[$i];
  ($ser,$cgname,$devs) = split (/:/, $entry, 3);
  $mightyinfo{ser_dg_devs}->{$ser}->{$cgname} =  $devs;
}

#Process each argument and produce the output
foreach $ser ( keys % {$mightyinfo{ser_dg_devs} } ) {
  print "List of devs for array ............ $ser\n";
  foreach $cgname ( keys % { $mightyinfo{ser_dg_devs}->{$ser} } ) {
    print "Constistency Group     ............ $cgname\n";
    #$count is used to assign the device number to each device
    $count = 1;

    #splitting the devices given for each CGname seperated by "," and saving them into array
    @devsarray = split(/,/,$mightyinfo{ser_dg_devs}->{$ser}->{$cgname} );

    # Procecc each element from each array entry
    foreach $dev_temp ( @devsarray ) {
      #If the entry contains "-" - it means it is a range of devices
      if ( $dev_temp =~ /-/ ) {
        ( $firstdev, $lastdev ) = split ( /-/,$dev_temp );
        #Remove the hash from the device number to generate a pure hex number such as 3F05
        #$firstdev =~ s/://g;
        #$lastdev =~ s/://g;

        # Convert the hexadecimal number to decimal to be used in range in for loop
        $firstdev_dec = hex ($firstdev);
        $lastdev_dec  = hex ($lastdev);

        # Start from first decimal number up to last decimal number
        for $devnum ( $firstdev_dec..$lastdev_dec ) {
          # Convert it back into hexadecimal format such as 3F05
          $device = sprintf ( "%X", $devnum );

          # Insert ":" into the hexadecimal number to look like 3F:05
          substr( $device, 2, 0 ) = ":";

          # Prepare the devicename within CG for second colum of horcm file
          $devname = "$cgname"."_"."$count";

          # Print the output and increase the count
          print "$cgname $devname $ser $device\n";
          $count = $count + 1;
        }
      } else {
        # Because this is not a range, it is a single number provided. 
        # Prepare its device name and display the output
        $devname = "$cgname"."_"."$count";

        # Insert ":" into the hexadecimal number to look like 3F:05
        substr( $dev_temp, 2, 0 ) = ":";

        print "$cgname $devname $ser $dev_temp\n";
        $count = $count + 1;
      }
    }
  }
  print "\n";
}

, ,

sanaswati
No comments yet.

Leave a Reply

*