Well I found a pretty simple solution given that no log files in /var/log are not to be truncated. Simply:
cat /dev/null > whatever.log
Now to do it to the whole directory recursively...
Don't really understand what that does that what I've posted doesn't do? I assumed you wanted to remove all logs, not just a specific log.
Regardless, both methods will truncate files.
Bash isn't really my strong point, but you could use PHP?
You could use opendir and readdir methods but you could also do something like this, which would allow you to recurse quite easily and parse it into a nice array for you to do some truncating with:
<?php
$_dir = "/var/log";
$cmd = "ls -lR $_dir";
$files=$out1=$out2=null;
exec($cmd, $out1, $out2);
foreach($out1 as $k=>$line){
if(substr($line, 0, 8) == '/var/log'){
$total = $out1[$k + 1];
$total = explode(" ", trim($total));
if($total[1] < 1) continue;
$dir = substr($line, 8);
$dir = substr($dir, 0, -1);
}
if(substr($line, 0, 8) != '/var/log' && substr($line, 0, 5) != 'total'){
$file = explode(":", $line);
$file = explode(" ", $file[1]);
$file = $file[1];
$files[$dir][]="$_dir$dir$file";
}
}
print_r($files);
?>