Php grep for RegEx recursiv通过目录
在我的PHP文件中,我想使用grep通过directorystructur进行递归搜索。 searchdirectory和主机名由变量提供。($path和$u POST['host\u select'])) 我试过这个:Php grep for RegEx recursiv通过目录,php,regex,recursion,grep,Php,Regex,Recursion,Grep,在我的PHP文件中,我想使用grep通过directorystructur进行递归搜索。 searchdirectory和主机名由变量提供。($path和$u POST['host\u select'])) 我试过这个: <?PHP function read_hostfile() { $path = '/omd/sites/test/etc/icinga/conf.d/objects'; $string= $_POST['host_select']; $shellcommand = "g
<?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);
.
.
?>
文件()有一个错误:
您不需要在
模式之前和之后使用*
试试这个:
$shellcommand = "grep -E -r -i --include='cfg host_name.*switch' $path";
进入要搜索的目录,然后运行grep-E-r'host\u name[\s]*switch*'*
命令*
afterh
表示我得到的h
次数为零或更多:grgrep-E-r'host\u nameswitch'/omd/sites/test/etc/icinga/conf.d/objects/-bash:grgrep:command not found |我尝试了grep-E-r'host\u nameswitch'/omd/sites/test/etc/icinga/conf.d/objects/,尽管没有结果,但rgrep是一个拼写错误。我编辑我的主要问题以使我的问题更清楚。命令shell_exec()不起作用。我得到了以下代码:|我已经尝试了exec
和shell\u exec
,结果相同。
execgrep: unknown directories method
file()PHP Warning: file(): Filename cannot be empty in /home/thomas/configpage_icinga_test/test.php on line 14
$shellcommand = "grep -E -r -i --include='cfg host_name.*switch' $path";