#!C:\Perl\bin\perl.exe use Win32; use IO::Handle; use File::Find; #use strict; #use warning; #################################################################################### #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. # # # #expect values 'on|off' ($SEC,$MIN,$HOUR, $DAY, $MON, $YEAR)= (localtime) [0..6]; $year=$YEAR+1900; $month=$MON+1; $day=$DAY; $date="$year\_$month\_$day"; $LOG="E:/Temp/inyrohs/maintenanceMode_$date.log"; $tempfile="E:/Temp/inyrohs/temp/outagenodes_temp.txt"; $serverlist="E:/Temp/INYROHS/serverlist.txt"; open( MYFILE, "E:/Temp/INYROHS/serverlist.txt"); @outagenodes=; #$ref2MYFILE=\*MYFILE; close MYFILE; open ( MYTEMPLIST, "E:/Temp/INYROHS/temp/outagenodes_temp.txt"); @tempnodes=; # $ref2MYTEMPLIST=\*MYTEMPLIST; close MYTEMPLIST; print "@outagenodes\n"; #Below subroutine call is to delete the temp file if already existing so that the outage is not run on the previously entered servers. deleteTemp($tempfile,$serverlist); 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"; $maintMode=$ARGV[0]; chomp($maintmode); print "maintMode: $maintMode:\n"; foreach $NODES (@tempnodes) { printLog("Node: $NODES, processing...\n"); if($maintMode =~ m/on/) { print "entered loop \n"; $cmd="ovownodeutil -outage_node -unplanned -disable_heartbeat -delete_msgs -node_name $NODES -$maintMode "; print "$cmd\n"; system($cmd); print "done with command"; } elsif($maintMode=~ m/off/) { printLog("Putting the server $NODES in the outage.\n"); $cmd="ovownodeutil.cmd -outage_node -unplanned -disable_heartbeat -delete_msgs -node_name $NODES -$maintMode"; $cmdstop="opcragt -stop $NODES"; $cmdstart="opcragt -start $NODES"; print "$cmd\n"; system($cmd); print "$cmdstop\n"; system($cmdstop); print "$cmdstart\n"; system($cmd); system($start); } } sub printLog { my ($logLine) = @_; chomp($logLine); $logLine=$logLine . "\n"; print "$logLine"; print LOG "$logLine"; } sub deleteTemp { my ($delTemp)=@_[0]; $cmddelTemp="DEL /Q $delTemp\n"; system($cmddelTemp); my($serverlist)=@_[1]; $cmdcopy="xcopy $serverlist $delTemp"; system($cmdcopy); }