xp-sp3
See code below.
In Webuilder, if I comment out the function and the loop, the syntax check shows "No syntax errors were found."
If I enable either or both - function and loop - Webuilder syntax check throws "Ng panda.php"
I'm running the script in a dos window. With or without the function and/or loop it runs without blowing up, although it doesn't produce the complete "results" file that I need.
- If the directory does not have the "results" file, the script creates a 0 length "results" file with the correct name.
- If the "results" file exists, the script does not overwrite or delete the existing file. It also leaves it where length=0.
- If I delete the "results" file, and run the script, all that it does is to create a new 0-length file.
Question #1: What is "Ng panda.php"?
Question #2: Will understanding that error message help me debug the script?
Question #3: Can anyone out there tell me what's wrong? Is it the code? Is there a more fundamental error, e.g. 'you can't run that kind of script in a dos window' or some such mistake.
Code: Select all
<?php /* -- compare nslookup for hostname & ip address -- */
// declare vars
$dir = "."; // folder for input and results files
$thisday = date(Ymd); // date used in file names ex: 20100316
$filein = $thisday . "-panda.txt"; // input file
$fileout = $thisday . "-results.txt"; // results file
$handlei = fopen($filein, 'r'); // open input file read-only
$texta = " - computers without Panda\n"; // part of header line in results page
$textb = $thisday.$texta;
/* ---- sanity check
print $filein . "\n";
print $fileout . "\n";
print $textb . "\n";
*/
fopen($fileout, 'w'); // open the output file for write
fwrite($fileout, $textb); // print header line at top of results page
// leave results page open for more writes
/* ---- example of vars in function below
$data = OHE-CL30,10.11.1.59
$z = 19 // count of chars in entire line
$b = 8 // location of comma
$a = 0,7 "OHE-CL30" // 1st substring in $data
$c = 9,18 "10.11.1.59" // 2nd substring in $data
*/
function(reportit)
{
// get values for vars
fopen($filein,'r'); // open the input file
$data=fgets($handlei,60); // the string being read
$z = strlen($data); // how many chars in entire line
$b = strpos($data,","); // find the comma
$a = substr($data,0,($b-1)); // hostname
$c = substr($data,($b+1),($z - 1)) // ip address
// compare ip & host name
print " \n ----------------- \n";
shell_exec(nslookup $a >> $fileout);
shell_exec(nslookup $c >> $fileout);
print " \n ----------------- \n";
}
while (!feof($handlei))
{
reportit() // do it;
}
close ($filein);
close ($fileout);
?>