Hi , I will show you my complete code , which after using strict and warnings is not getting complied.
#!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. # # # #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"; my $tempfile="E:/Temp/inyrohs/temp/outagenodes_temp.txt"; my $serverlist="E:/Temp/INYROHS/serverlist.txt"; open( MYFILE, "<E:/Temp/INYROHS/serverlist.txt"); @outagenodes=<MYFILE>; close MYFILE; open ( MYTEMPLIST, "<E:/Temp/INYROHS/temp/outagenodes_temp.txt"); @tempnodes=<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"; my $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"; #$cmdstopopcmona="ovdeploy -cmd "ovc -stop opcmona" -host +$NODES"; #$cmdstopopcle="ovdeploy -cmd "ovc -start opcle" -host $NO +DES"; #$cmdstartopcmona="ovdeploy -cmd "ovc -start opcmona" -hos +t $NODES"; #$cmdstartopcle="ovdeploy -cmd "ovc -start opcle" -host $N +ODES"; # $cmdstart="opcragt -start $NODES"; print "$cmd\n"; system($cmd); # print "$cmdstopopcmona\n"; # # system($cmdstopopcmona); # # print "$cmdstopopcle"; # system($cmdstopopcle); # print "$cmdstartopcle\n"; # system($cmdstartopcle); # #print "$cmdstart\n"; # system($cmd); # system($start); } } sub printLog { my ($logLine) = @_; chomp($logLine); $logLine=$logLine . "\n"; print "$logLine"; print LOG "$logLine"; } sub deletTemp { my ($delTemp,$serverlist)=@_; print "temp: $delTemp\n"; print "serv: $serverlist\n"; unlink $delTemp; copy($serverlist,$delTemp); }
And below are the errors:
E:\Temp\inyrohs>perl outage_nodes.pl on Possible unintended interpolation of @outagenodes in string at outage_ +nodes.pl line 48. Variable "$LOG" is not imported at outage_nodes.pl line 59. Global symbol "$SEC" requires explicit package name at outage_nodes.pl + line 20. Global symbol "$MIN" requires explicit package name at outage_nodes.pl + line 20. Global symbol "$HOUR" requires explicit package name at outage_nodes.p +l line 20. Global symbol "$DAY" requires explicit package name at outage_nodes.pl + line 20. Global symbol "$MON" requires explicit package name at outage_nodes.pl + line 20. Global symbol "$YEAR" requires explicit package name at outage_nodes.p +l line 20. Global symbol "$year" requires explicit package name at outage_nodes.p +l line 22. Global symbol "$YEAR" requires explicit package name at outage_nodes.p +l line 22. Global symbol "$month" requires explicit package name at outage_nodes. +pl line 23. Global symbol "$MON" requires explicit package name at outage_nodes.pl + line 23. Global symbol "$day" requires explicit package name at outage_nodes.pl + line 24. Global symbol "$DAY" requires explicit package name at outage_nodes.pl + line 24. Global symbol "$date" requires explicit package name at outage_nodes.p +l line 25. Global symbol "$year" requires explicit package name at outage_nodes.p +l line 25. Global symbol "$month" requires explicit package name at outage_nodes. +pl line 25. Global symbol "$day" requires explicit package name at outage_nodes.pl + line 25. Global symbol "$LOG" requires explicit package name at outage_nodes.pl + line 27. Global symbol "$date" requires explicit package name at outage_nodes.p +l line 27. Global symbol "@outagenodes" requires explicit package name at outage_ +nodes.pl line 37. Global symbol "@tempnodes" requires explicit package name at outage_no +des.pl line 44. Global symbol "@outagenodes" requires explicit package name at outage_ +nodes.pl line 48. Global symbol "$LOG" requires explicit package name at outage_nodes.pl + line 59. Global symbol "$LOG" requires explicit package name at outage_nodes.pl + line 59. Global symbol "$maintMode" requires explicit package name at outage_no +des.pl line 61. Global symbol "$HOUR" requires explicit package name at outage_nodes.p +l line 61. Global symbol "$MIN" requires explicit package name at outage_nodes.pl + line 61. Global symbol "$SEC" requires explicit package name at outage_nodes.pl + line 61. Global symbol "$date" requires explicit package name at outage_nodes.p +l line 63. Global symbol "$maintmode" requires explicit package name at outage_no +des.pl line 71. Global symbol "$NODES" requires explicit package name at outage_nodes. +pl line 76. Global symbol "@tempnodes" requires explicit package name at outage_no +des.pl line 76. Global symbol "$NODES" requires explicit package name at outage_nodes. +pl line 83. Global symbol "$cmd" requires explicit package name at outage_nodes.pl + line 95. Global symbol "$NODES" requires explicit package name at outage_nodes. +pl line 95. Global symbol "$cmd" requires explicit package name at outage_nodes.pl + line 97. Global symbol "$cmd" requires explicit package name at outage_nodes.pl + line 99. Global symbol "$NODES" requires explicit package name at outage_nodes. +pl line 112. Global symbol "$cmd" requires explicit package name at outage_nodes.pl + line 114. Global symbol "$NODES" requires explicit package name at outage_nodes. +pl line 114. Global symbol "$cmd" requires explicit package name at outage_nodes.pl + line 128. Global symbol "$cmd" requires explicit package name at outage_nodes.pl + line 131. Execution of outage_nodes.pl aborted due to compilation errors.

In reply to Re^2: Subroutine to delete one file and copy one file to another by shroh
in thread Subroutine to delete one file and copy one file to another 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.