shroh has asked for the wisdom of the Perl Monks concerning the following question:
#!C:\Perl\bin\perl.exe use Win32; use IO::Handle; use File::Find; use strict; use warnings; use File::Copy qw(copy); ###################################################################### +############## #This script is created to put the servers in unplanned outage as part + of the tasks# #that are received to stop the monitoring on the servers #due to some maintenance activity on the servers. # # # require "E:/Temp/inyrohs/omwNodeDetails.pm"; #expect values 'on|off' my ($SEC,$MIN,$HOUR, $DAY, $MON, $YEAR)= (localtime) [0..6]; my $year=$YEAR+1900; my $month=$MON+1; my $day=$DAY; my $date="$year\_$month\_$day"; my $LOG="E:/Temp/inyrohs/maintenanceMode_$date.log"; my $serverlist="E:/Temp/INYROHS/serverlist.txt"; open( MYFILE, "E:/Temp/INYROHS/serverlist.txt") or die "Can't open '$ +serverlist': $!"; my @outagenodes=<MYFILE>; #print "@outagenodes\n"; my $maintMode=$ARGV[0]; chomp($maintMode); open (LOG,">> $LOG") or die "Can't open $LOG file: $!\n"; printf LOG ("\nTime is %02d:%02d:%02d.\nStarting the maintenance mode +process to turn $maintMode outages.\n\n", $HOUR, $MIN, $SEC); #print "$date \n"; #print "starting the process \n"; #print "maintMode: $maintMode:\n"; if($maintMode =~ m/on/) { foreach my $NODES (@outagenodes) { my @parts=split /\./, $NODES; my $hostname=$parts[0]; chomp($hostname); my $fqdn = getNodeAttributes($hostname,"PrimaryNodeName"); print "$hostname\n"; #printLog("Node: $NODES, processing...\n"); #print "entered loop \n"; my $cmd="ovownodeutil.cmd -outage_node -unplanned -disable_ +heartbeat -delete_msgs -node_name $fqdn -$maintMode "; print "$cmd\n"; `$cmd`; print "done with command\n"; } } elsif($maintMode=~ m/off/) { foreach my $NODES (@outagenodes) { my @parts=split /\./, $NODES; my $hostname=$parts[0]; chomp($hostname); my $fqdn = getNodeAttributes($hostname,"PrimaryNodeName"); print "$hostname\n"; printLog("Node: $NODES, processing...\n"); printLog("Bringing the server $NODES out of outage.\n"); my $cmd="ovownodeutil.cmd -outage_node -unplanned -disable_ +heartbeat -delete_msgs -node_name $NODES -$maintMode"; my $cmdresopcmona="ovdeploy -cmd \"ovc -restart opcmona\" - +host $NODES"; my $cmdresopcle="ovdeploy -cmd \"ovc -restart ocpmona\" -ho +st $NODES"; print "$cmd\n"; `$cmd`; print "$cmdresopcmona\n"; `$cmdresopcmona`; print "$cmdresopcle\n"; `$cmdresopcle`; } } sub printLog { my ($logLine) = @_; chomp($logLine); $logLine=$logLine . "\n"; print "$logLine"; print LOG "$logLine"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Clear the contents of the text file
by roboticus (Chancellor) on Jul 22, 2015 at 00:27 UTC | |
|
Re: Clear the contents of the text file
by kernal (Initiate) on Jul 22, 2015 at 02:29 UTC | |
by james28909 (Deacon) on Jul 22, 2015 at 05:54 UTC | |
by Anonymous Monk on Jul 22, 2015 at 06:59 UTC | |
|
Re: Clear the contents of the text file
by Anonymous Monk on Jul 22, 2015 at 00:30 UTC | |
by shroh (Acolyte) on Jul 22, 2015 at 00:40 UTC | |
by 1nickt (Canon) on Jul 22, 2015 at 01:29 UTC | |
by Anonymous Monk on Jul 22, 2015 at 01:41 UTC | |
by 1nickt (Canon) on Jul 22, 2015 at 01:46 UTC | |
| |
by Anonymous Monk on Jul 22, 2015 at 01:08 UTC | |
|