#!/usr/software/bin/perl # $Id: //depot/prod/test/main/storage/hdd/NADQ_SEA/TEST_SCRIPTS/NDATE4.1/SUPPORT_SCRIPTS/update_filerinfo.thpl#1 $ # Copyright (c) 2005 Network Appliance, Inc. # All rights reserved # ## @summary Mode ## update_filerinfo ## ## @description ## This script will add the c_system parameter under filer configuration file ## ## ## @status Automated ## @auther vpankaj@netapp.com ## @burt ## @change YY/MM/DD from auther: Description of the change ## ############################################################################# ######################################### ### Library functions ########################################## # Compiler directives. use strict; # Module imports use FileHandle; ######################################### ### Initialization/declaration ######################################### sub trim($); # Global variables my $flag = 0; ## flag Varibale used, if c-system parameter are present in the config file. my $flag_chk = 0; ## flag Varibale used, if c-system parameter are not present in the config file. my ($mgmt_ip ,$Password); my $Home = $ENV{HOME}; if (!($Home)) { print "\n Environment variable HOME is not set: Home = $Home \n"; exit 0; } ## end if (!($Home)) chdir("$Home/NDATE/FILER_INFO"); system("sudo chmod 777 *"); my @host_files = <*>; foreach my $filername (@host_files) { my @total_data_new=(); $filername = trim($filername); if (($filername =~ /_C$/)&&($filername !~ /FILERS_LIST/)) { print "Reading the file $filername....\n"; open(FH,"$filername"); my @total_data = ; foreach my $line (@total_data) { ##check : availability of c-system parameter in config file if ($line=~/c-system/){ $flag_chk = 1; next; } } foreach my $line (@total_data) { if ($line=~/c-system/){ $flag = 1; next if ($line=~/c-system/); }elsif($flag == 1){ push(@total_data_new , "conn c-system {conntype=ssh-persist;connhost=$mgmt_ip;username=admin;password=$Password}\n" ); push(@total_data_new , "conn c-system {initial_command=\"set -privilege test;systemshell -node local\"}\n" ); push(@total_data_new , "conn c-system {prompt_password=$Password}\n\n" ); $flag = 0; }elsif(($flag_chk == 0) && ($line=~/c-login|MODEL/)){ push(@total_data_new , $line); push(@total_data_new , "conn c-system {conntype=ssh-persist;connhost=$mgmt_ip;username=admin;password=$Password}\n" ); push(@total_data_new , "conn c-system {initial_command=\"set -privilege test;systemshell -node local\"}\n" ); push(@total_data_new , "conn c-system {prompt_password=$Password}\n" ); $flag_chk = 1; }else{ if($line=~/^MGMT_IP$\s*\=\s*(\S+)/){ $mgmt_ip = $1; } if($line=~/default_password\s*\=\s*(\S+)/){ $Password = $1; } push(@total_data_new , $line); } } close FH; ##Open the file in write mode permission and add the parameter## print "Updating the file $filername....\n\n"; open( FD, ">$filername"); print( FD @total_data_new ); close FD; } ##if (($filername =~ /_C$/)&&($filername !~ /FILERS_LIST/)) } ## end foreach my $filername (@host_files) if ($flag_chk == 1){ print "**All the C-mode config file are updated successfully**\n"; }else{ print"**No C-mode config file are present under $Home/NDATE/FILER_INFO. Please check manually**\n"; } sub trim($) { my $string = shift; $string =~ s/^\s+|\s+$//gm; return $string; }