php 脚本来执行 bash 脚本并在网页上显示结果。

标签 php linux bash

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

我编写了一个接受单个参数(电子邮件地址)的 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>

在index.php中你可以放这样的代码:

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

关于php 脚本来执行 bash 脚本并在网页上显示结果。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14630977/

相关文章:

node.js - 无法创建/dev/stdout : No such device or address

linux - 如何在 Linux 上启动时自动启动该应用程序?

PHP ->exec() 成功,但表中没有存储任何内容?

linux c/c++ 编程 telnet 连接 io 重定向

c++ - 如何安全终止多线程进程

linux - 在 bash 脚本中使用 for 循环在多行命令中插入行

bash - 函数在 bash 脚本中不起作用 - 错误消息与 '\r' 相关

php - Symfony 表单 - 如何在验证时添加一些逻辑

php - upload_max_filesize - 完美的 ubuntu 服务器 ISPConfig 3

PHPStorm:由 include/require 引起的 undefined variable