【问题标题】:grep for RegEx recursiv through directoriesgrep for RegEx 通过目录递归
【发布时间】: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 的零次或多次

标签: php regex recursion grep


【解决方案1】:

pattern 之前和之后都不需要*

试试这个:

$shellcommand = "grep -E -r -i --include='cfg host_name.*switch' $path";

【讨论】:

  • 我得到:grgrep -E -r 'host_nameswitch' /omd/sites/test/etc/icinga/conf.d/objects/ -bash: grgrep: command not found|我试过 grep -E -r 'host_nameswitch' /omd/sites/test/etc/icinga/conf.d/objects/ 虽然没有结果
  • grgrep 是一个拼写错误。我编辑了我的主要问题,以使我的问题更清楚。
  • 命令 shell_exec() 不起作用。我有以下代码:| |命令“shell_exec()”无法完成。我试过回声"";在它之后,但它没有看到它。
  • 我已经尝试过execshell_exec,结果相同。
猜你喜欢
  • 1970-01-01
  • 2010-12-31
  • 1970-01-01
  • 1970-01-01
  • 2011-02-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-05
  • 1970-01-01
相关资源
最近更新 更多