Thanks! I was stuck on this one. I knew where I was going wrong, just not what was going wrong. Now I can go to lunch. :) Obviously I am not the PERL master and I certinly appericate the suggestions to improve my coding. I didn't know about the LWP, sounds usefull. I am gonna have to read up on that one. Thanks again.
-Skip
Hopenfully someone can help me with this one. Essentially the script below should run GETHTTP.EXE and save the output to a text file. It should then open the text file, dump it into an array and search for a particular string. If the string is found it should then write a line to a log file and end. If the string is not found it should run a little VBScript that will reconfigure a router. I think the problem is with the conditional statement that searches the array and creates the "$decide" var. Maybe I am doing something totally stupid, maybe it's just something small I am missing. If comeone could shed some light on this it would be greatly appericated. Thanks in advance. Here is the script. I commented it so it should be pretty self explanitory.
-Skip
# Get the all the values for current time ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $ +IsDST) = localtime(time); $RealYear = $Year + 1900; #Create proper format for year $RealMonth = $Month + 1; #Add 1 to month because PERL starts @ 0 # Add leading "0" to Miniute if less than 10 if($Minute < 10) { $Minute = "0". $Minute; } # Create a Log File open (fail_log,">>faillog.txt"); # Create Router Re-Configuration script run command $rtr_cfg="wscript.exe rtr-telnet.vbs"; # Create a var that holds the string to be found in the "gethttpbuff" +results $search="</html>"; # Create & run "GETHTTP.EXE" command. Redirect output to "gethttpbuff. +txt" $gethttp="gethttp.exe http://www.blahblahblah.com>gethttpbuff.txt"; system($gethttp); #it seems like the code below is what doesn't work right. if (&Search_Buff($decide == "1")){ &Site_Up; } else { &Site_Down; } # Sub to search gethttpbuff.txt for a string & return 0 or 1 sub Search_Buff { # Open hethttpbuff.txt file, create an array with the data & close fil +e. End if file is locked. open (gethttpbuff, "gethttpbuff.txt") || die("Could not open file!"); @array = <gethttpbuff>; close(gethttpbuff) # If search string is found make var equal to "1". If the search strin +g is not found make var equal to "0" foreach $line (@array) { if ($line =~ /$search/) { $decide = "1"; } else { $decide = "0"; } } sub Site_Up { # site is up print fail_log ($Hour); print fail_log (":"); print fail_log ($Minute); print fail_log ("-and all is well on "); print fail_log ($RealMonth); print fail_log ("-"); print fail_log ($Day); print fail_log ("-"); print fail_log ($RealYear); print fail_log ("\r\n"); } sub Site_Down { # Site is down print fail_log ("Blahblahblah.com has gone down! "); print fail_log ($Hour); print fail_log (":"); print fail_log ($Minute); print fail_log (" "); print fail_log ($RealMonth); print fail_log ("-"); print fail_log ($Day); print fail_log ("-"); print fail_log ($RealYear); print fail_log ("\r\n"); system($rtr_cfg); } }
In reply to Problem Searching an array for a string... Please Help! by XehNib
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |