sitetester.sh lets you run automated tests on websites. more infos below the code.
sitetester.sh
#!/usr/bin/php
<?
function cleanUp()
{
if (file_exists('sitetest_cookies.txt')) exec ('rm sitetest_cookies.txt');
if (file_exists('sitetest_out.txt')) exec ('rm sitetest_out.txt');
}
function cleanUpAndDie($ReturnValue)
{
cleanUp();
exit ($ReturnValue);
}
function processUrl($url)
{
unset($out);
$time_start_m = microtime();
exec('time curl -L -c sitetest_cookies.txt -b sitetest_cookies.txt -A "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.5) Gecko/20061201 Firefox/2.0.0.5 (Ubuntu-feisty)" "'.$url.'" 2>/dev/null', $out);
$time_end_m = microtime();
$time_start = explode(' ', $time_start_m);
$time_start = $time_start[1] + $time_start[0];
$time_end = explode(' ', $time_end_m);
$time_end = $time_end[1] + $time_end[0];
echo date('Y-m-d:H:i:s');
echo ' ';
echo round(($time_end - $time_start), 5);
echo ' ';
return join("\n",$out);
}
// ----------------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------------
cleanUp();
$args=$_SERVER['argv'];
if (!isset($args[1]))
{
die("Usage: sitetest.php \n");
}
$urls=file($args[1]);
$mode='normal';
foreach ($urls as $url)
{
$line=trim($url);
if (strlen($line)<1) continue;
if (strpos($line, '//')===0) continue;
if ($mode=='comment' && strpos($line, '*/')!==false)
{
$mode='normal';
continue;
}
if ($mode=='comment') continue;
if (strpos($line, '/*')===0)
{
$mode='comment';
continue;
}
if ($line=='die();')
{
echo "\ndie();\n\n";
cleanUpAndDie(0);
}
$split =strpos($line,' ');
$url =substr($line,0,$split);
$pattern=substr($line,$split+1);
$out=processUrl($url);
$result=preg_match('§'.$pattern.'§m', $out);
echo $url.' '.$pattern.' '.($result ? '(ok)' : '(not found!)')."\n";
if(!$result)
{
echo "\n--- !!! Something was not as expected !!! ---\n";
echo "writing to sitetest_out.txt!!\n";
$fh=fopen('sitetest_out.txt','w');
fwrite($fh,$out);
fclose($fh);
echo "Cookie file will not be deleted\n\n";
die();
}
}
echo "\nEverything is ok and the sky is blue.\n\n";
cleanUpAndDie(0);
?>
Below is a testfile. You run it like this:
./sitetester.sh urls.txt
urls.txt
www.example.com something
www.example.com/someurl/ somethingelse
www.someotherexample.com/some/url.php something