php页面传参给shell脚本

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>MAC search</title>

</head>

<body align="middle" bgcolor="gray">

<h1><font size="20" face="Verdana" color="blue">MAC search</font></h1>

<form action="" method="post">

MAC:

<input type="text" name="mac" size="20"/>

<input type="submit" value="submit"/>

</form>

<?php

if(isset($_POST['mac'])&&$_POST['mac']!=''){

        $mac=$_POST['mac'];

$output = shell_exec("macsearch $mac");

echo "$output";

}

?>

</body>

</html>

分析如下:

    1.通过表单传入一个参数“mac”        

        <form action="" method="post">

        MAC:

        <input type="text" name="mac" size="20"/>

        <input type="submit" value="submit"/>

        </form>

    2.通过php传入参数并且运行shell脚本     

        <?php

        if(isset($_POST['mac'])&&$_POST['mac']!=''){

                $mac=$_POST['mac'];

        $output = shell_exec("macsearch $mac");

        echo "$output";

        }

        ?>

 

补充:今天遇到一个问题,通过php页面执行这个脚本的时候无效,macsearch脚本中的wget命令未执行(macsearch脚本在博文《字符串按位数分隔》中有)

    1.切换到一个普通用户执行macsearch发现也不执行wget命令

    2.检查目录权限,发现/srv/macsearch/record权限为755,普通用户无写入权限,所以执行:

        chmod -R 777 /srv/macsearch/record

    3.问题解决

 

posted @ 2019-08-30 16:15  ashaff  阅读(462)  评论(0编辑  收藏  举报