Hi Monks,
I am trying to create a subroutine in perl which takes two files as arguments in the subroutine call. The role of subroutine is to delete first file and copy the contents of second file in a new file. But i am not able to do that, may be because i dont know how to pass the files as arguments.
My code is below: deleteTemp is the subroutine.
#!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=<MYFILE>;
#$ref2MYFILE=\*MYFILE;
close MYFILE;
open ( MYTEMPLIST, "E:/Temp/INYROHS/temp/outagenodes_temp.txt");
@tempnodes=<MYTEMPLIST>;
# $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_heartb
+eat -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_he
+artbeat -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);
}
I am getting the below error:
E:\Temp\inyrohs>perl outage_nodes.pl on
Invalid switch - "Temp".
Invalid number of parameters
2015_7_19
starting the process
maintMode: on: