Jump to content

grep + php


Aretai

Recommended Posts

Hi,

 

I'm using Solaris 10. I want to create a simple on-line search form for the files stored on my OS (it's trusted environment). The problem for me is redirecting to a different directory. My php file is stored in:

"/usr/local/php" and I would like to search for the content of the files stored in the "/home/test/"

 

The script itself is working for the "ls" command (I get files stored in /home/test), however when I run it for diff command it displays info relevant for "/usr/local/php".

 

What should be changed?  ???

 

<?php
   $filepath = "home/test";
   $len = strlen($filepath);
   $command="pwd";
   //$command="ls -l \"{$filepath}\"";
   //$command="ls -l \"{$filepath}\"";
   $command = "grep -i test * \"{$filepath}\"";

   $output = shell_exec($command);
   echo "<pre>$output</pre>";
?>

Link to comment
https://forums.phpfreaks.com/topic/40697-grep-php/
Share on other sites

<?php
   $filepath = "home/test";
   $len = strlen($filepath);
   $command="pwd";
   //$command="ls -l \"{$filepath}\"";
   //$command="ls -l \"{$filepath}\"";
   $command = "grep -i 'test' /home/me/my_docs/* \"{$filepath}\"";

   $output = shell_exec($command);
   echo "<pre>$output</pre>";
?>

 

Try putting the path in front of the files you want to search (like I did above)

 

Also note the quotes around 'test'.

 

monk.e.boy

Link to comment
https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196939
Share on other sites

<?php
   $filepath = "home/test";
   $len = strlen($filepath);
   $command="pwd";
   //$command="ls -l \"{$filepath}\"";
   //$command="ls -l \"{$filepath}\"";
   $command = "grep -i 'test' /home/me/my_docs/* \"{$filepath}\"";

   $output = shell_exec($command);
   echo "<pre>$output</pre>";
?>

 

Try putting the path in front of the files you want to search (like I did above)

 

Also note the quotes around 'test'.

 

monk.e.boy

 

Tried this - even without assigning directory to a variable (i.e. dir is fixed)

 

  $command = "grep -i 'test' /home/test/*";

 

but it's not working. However this command is working under OS. Wonder what can cause an error - I only get a blank page (and I know there should be some result). Tried to debug with:

 

<?php

ini_set("display_errors","1");

?>

but nothing is returned :(

 

Aretai

 

Link to comment
https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196958
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.