hi Perl Experts, i am getting the compilation error while executing the script . Below is the code and errors that i am getting.
#!C:\Perl\bin\perl.exe use strict; use warnings; # # 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. # Author : ROHIT SHARMA (INYROHS) my $path = 'E:/scripts/OutageNodes/'; require $path.'omwNodeDetails.pm'; &main(); sub main { my ($mode,@nodes); $mode=&get_mode(); @nodes=&get_node(); if( $mode eq 'enable'){ &enable_unplanned_outage(@nodes); } elsif($mode eq 'disable'){ &disable_unplanned_outage(@nodes); } else { &printLog("Error invalid Mode $mode");} # clear serverlist printLog ("Truncating serverlist"); open( SRV,'>',$path.'serverlist.txt') or die "Can't open SRV '$path.serverlist': $!"; close SRV; } sub get_mode { # expect values 'enable|disable' my $maintMode = lc $ARGV[0]; chomp($maintMode); if ($maintMode ne "enable") && ($maintMode ne "disable"){ $maintMode="error"; } return ($mainMode); } sub get_node { my ($sPath,$sFile,$sInfile,$sText, @sContent,@serverlist); $sPath="e:/scripts/Outage_nodes"; $sInFile=$sPath.'serverlist.txt'; ##checks if the file exists and pulls the info out if (-e "$sInFile"){ open(INFILE, "<$sInfile") or die "Can't open INFILE + '$sInfile': $!"; while (<INFILE>){ chomp; $sText="$_"; push(@sContent, $sText); } + close INFILE; }else{ &printLog("Error Cannot open $sInFile"); } # check serverlist had entries if (@sContent == 0){ printLog("ERROR No nodes found in $serverlist"); exit; } #get FQDN************ for my $NODE (@sContent){ my ($hostname) = split /\./, $NODE; my $fqdn = getNodeAttributes($hostname,'PrimaryNodeName'); if(length($fqdn) < 1) { printLog("No value returned from WMI, node ($NODE) doesn't ex +its in OMW."); next; } push(@serverlist,$fqdn); return(@serverlist); } sub enable_unplanned_outage { my ($FQDN,$mode,$cmd,@serverlist,$output); @sContent=@_[0..$#_]; foreach $FQDN (@sContent) { $cmd = "ovownodeutil.cmd -outage_node -unplanned -disable_heartb +eat -delete_msgs -node_name $FQDN -on "; printLog("Putting the server $FQDN into outage"); `$cmd`; printLog(`cmd`); } } sub disable_unplanned_outage { my ($FQDN, $mode, $cmd, $cmdresopcmona, @sContent,$output); @sContent = @_[0..$#_]; ####When the servers is brough out of maintenance the agent has to be +recycled to reset all the monitors. foreach $FQDN (@sContent) { $cmd = "ovownodeutil.cmd -outage_node -unplanned -disable_hear +tbeat -delete_msgs -node_name $FQDN -off "; printLog("Node $FQDN >>> off"); $cmdresopcmona = "ovdeploy -cmd \"ovc -restart opcmona\" -host $FQ +DN"; $output=`$cmd`; printLog($cmd); `$cmd`; printLog($output); printLog($cmdresopcmona); `$cmdresopcmona`; } } sub prinLog { my ($sPath, $logFile, $sOutFile, $sText, $date_time, $SEC, $MIN, +$HOUR, $DAY, $MON, $YEAR,$now); #get date/time $SEC, $MIN, $HOUR, $DAY, $MON, $YEAR = (localtime) [0..6]; $date_time = $YEAR + 1900 . $MON + 1 . $DAY . " " . $HOUR . ": +" . $MIN . ":" . $SEC; #get log file parameters $sPath = "e:\\scripts\\outage_nodes"; #review - + change to a standard location $logFile=$sPath."maintenanceMode_$date.log"; my ($logLine) = @_; my $now = sprintf "%02d:%02d:%02d",(localtime)[2,1,0]; open (LOG,'>>',$logfile) or die "Can't open LOG '$logfile': $! +\n"; print LOG "$now $logLine\n"; close LOG; }
And the errors are
E:\scripts\OutageNodes>perl outage_nodes.pl enable "my" variable $sPath masks earlier declaration in same statement at ou +tage_nodes .pl line 80. "my" variable $sPath masks earlier declaration in same scope at outage +_nodes.pl line 82. "my" variable $sText masks earlier declaration in same scope at outage +_nodes.pl line 95. "my" variable $now masks earlier declaration in same scope at outage_n +odes.pl li ne 212. syntax error at outage_nodes.pl line 62, near ") &&" Global symbol "$maintMode" requires explicit package name at outage_no +des.pl lin e 69. syntax error at outage_nodes.pl line 72, near "}" Missing right curly or square bracket at outage_nodes.pl line 231, at +end of lin e Execution of outage_nodes.pl aborted due to compilation errors.

In reply to Compilation error in the perl script by shroh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.