【发布时间】:2014-07-24 07:41:52
【问题描述】:
在我的 PHP 文件中,我想使用 grep 通过目录结构进行递归搜索。 搜索目录和主机名由变量给出。 ($path 和 $_POST['host_select']) 我试过这个:
<?PHP
function read_hostfile()
{
$path = '/omd/sites/test/etc/icinga/conf.d/objects';
$string= $_POST['host_select'];
$shellcommand = "grep -E -r -i --include=*cfg 'host_name*switch' $path";
$result = exec($shellcommand);
$hostfile = file($result);
.
.
?>
我尝试如下编辑我的 grep 命令:
$shellCommand = "grep -E -d=read -r --include='cfg host_name*$string' $path";
file() 出现错误:
execgrep: unknown directories method
file()PHP Warning: file(): Filename cannot be empty in /home/thomas/configpage_icinga_test/test.php on line 14
【问题讨论】:
-
进入要搜索的目录,然后运行
grep -E -r 'host_name[\s]*switch*' *命令。*在h之后表示h的零次或多次