PHP script shell problem

Discussion in 'Programming/Scripts' started by Patrick Hansen, Oct 19, 2015.

  1. Patrick Hansen

    Patrick Hansen New Member

    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;
            }

        }
     
  2. sjau

    sjau Local Meanie Moderator

    not really sure where the error occurs in this part of the script. Could you elaborate more?
     
  3. florian030

    florian030 Well-Known Member HowtoForge Supporter

    Maybe $result['search_word'] contains whitspaces? Better use exec to get the output and the return-code
     
  4. Pablo Gil

    Pablo Gil New Member

  5. Gabri Shally

    Gabri Shally New Member

    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;
     

Share This Page