if_POST 然后执行一个或多个命令

if_POST then do command or commands

我在 PHP/HTML 页面上表现不佳。 但我想编写允许我这样做的脚本:

如果我在框中输入内容,则 PHP/HTML 文件执行 Linux 命令,例如:

 <form method='POST' name='name'><table width='100%' height='107' border='0'  id='Box'><tr>
      <td><input name='firstname' size='50' id="firstname" />
      </select></td>
    </tr>
    <tr>
      <td height='26' colspan='2'><input type='submit' value='DO' name='DO' id="DO" /></td>
    </tr>
    </table>
    </form>
<?php
if($_POST)
{ 
    $n = $_POST['firstname']);

echo exec(  command );
}
?>

我想执行这个命令

sshpass -p 'password' ssh -f   127.0.0.1 -l root -o StrictHostKeyChecking=no "./file.py  firstname  "

如果你想运行你写的命令的同时你应该使用JavaScript,但是如果你想运行你按下提交后的命令按钮(名为 DO 的那个),你应该把你的 php 代码放在一个不同的文件中,我们称之为 runCommand.php,然后在你的表单标签中添加这样的属性动作:

form action='runCommand.php' 

连同其他属性。

if (isset($_POST['firstname'])) {
  $command = "sshpass -p 'password' ssh -f   127.0.0.1 -l root -o StrictHostKeyChecking=no " . '"./file.py  ' . $_POST['firstname'] . '"';
  exec($command);
}

出于安全原因,我真的建议检查 $_POST['firstname'] 的内容,但我想您已经知道了。 ;)