PHP脚本,用于执行bash脚本并在网页上显示结果


php script to excute bash script and display results on webpage.

>我正在尝试创建非常简单的页面,该页面将在日志文件中查找电子邮件地址

我编写了一个 bash 脚本(带有复杂的 awk 和 sed 查询),它接受单个参数(电子邮件地址),它将显示如下输出。

DATE                    email                      phone 
31/1/2013               test@example.com           1800-000-000

如何创建一个仅接受电子邮件地址和搜索按钮的网页,该按钮将仅在后端执行 bash 脚本并将输出显示在屏幕上?

谢谢

 exec ("/path/to/script", $output); 

这会将结果输出到 $output 变量中。

然后,您可以创建页面。

<html>
<body>
<form action="index.php">
<input type="text" name="address" />
<input type="submit" value="Post!" />
</form>
</body>
</html>

在索引中.php你可以放置这样的代码:

<?php
     if ($_POST && $_POST['address']) {
          exec ("/path/to/script " . escapeshellarg($_POST['address']), $output); 
          echo $output;
     }