Hello, while trying to run my php script i get this error: sh: ?: No such file or directory although i can see in var_dump that the path is correct and does exists. If you have the answer please help Thanks! code below: PHP: public function readFiles(){ /*--------Declaring--------*/ $con = new database(); /*---------Database handling-------*/ $selectArgs = "SELECT * FROM search_words"; $runQuery = $con->con()->query($selectArgs); while($getQuery = $runQuery->fetch_assoc()): $words[] = $getQuery; endwhile; $dir = '/var/www/clients'; $sites = scandir($dir); $i = 0; foreach($sites as $siteToBeScanned): $scanDir = scandir("/var/www/clients/$siteToBeScanned/"); foreach($scanDir as $clients): if($siteToBeScanned == ".." || $siteToBeScanned == "." || $clients == "." || $clients == ".."): continue; else: foreach($words as $result): chdir("/var/www/clients/$siteToBeScanned/$clients/web"); shell_exec("grep -l -r ".$result['search_word']); //$virusQuery = "INSERT INTO virus_found (site,page) VALUES ('$siteToBeScanned','$dirToScan')"; //$con->con()->query($virusQuery); endforeach; endif; endforeach; endforeach; } }
Maybe $result['search_word'] contains whitspaces? Better use exec to get the output and the return-code
try this PHP: chdir("/var/www/clients/$siteToBeScanned/$clients/web");foreach($words as $result): shell_exec("grep -i -l -r \"$result[search_word]\" ."); //$virusQuery = "INSERT INTO virus_found (site,page) VALUES ('$siteToBeScanned','$dirToScan')"; //$con->con()->query($virusQuery);endforeach;