Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
执行带有PHP问题的BashScript_Php_Bash_Echo_Execute - Fatal编程技术网

执行带有PHP问题的BashScript

执行带有PHP问题的BashScript,php,bash,echo,execute,Php,Bash,Echo,Execute,我有一个bash脚本,它绑定到一些python脚本中,我希望在网页中执行这些脚本,并将它创建的文件放到网页上。目前,我根本无法执行脚本(多次测试脚本以确保它实际工作),而且我似乎无法找到错误所在。第一组代码来自我的/var/www中的“dashboard.php”文件。我已将脚本的权限更改为777,并使其可执行 <html> <body> <form action="welcome.php" method="post"> IP/CIDR Input:

我有一个bash脚本,它绑定到一些python脚本中,我希望在网页中执行这些脚本,并将它创建的文件放到网页上。目前,我根本无法执行脚本(多次测试脚本以确保它实际工作),而且我似乎无法找到错误所在。第一组代码来自我的/var/www中的“dashboard.php”文件。我已将脚本的权限更改为777,并使其可执行

<html>
<body>

<form action="welcome.php" method="post">
    IP/CIDR Input: <input type="text" name="cidriptext" />
    Single IP: <input type="checkbox" name="singlech" value="single" /> 
    CIDR Range: <input type="checkbox" name="cidrch" value="cidr" />    
<input type="submit" value="Submit">
</form>

<form action="welcome.php" method="post">
    List of IP's: <input type="text" name="listname" />
<input type="submit" value="Submit">
</form>

</body>
</html>
"; elseif(isset($_POST['cidrch']): shell_exec('/var/www/getStarted-c$ipcidr_text'); $output1=shell_exec('echo“CIDR Range”); 回显“$output1”; 其他(isset($_POST['singlech']): shell_exec('/var/www/getStarted-s$ipcidr_text'); $output2=shell_exec('echo“单IP”); 回显“$output2”; 其他: $output=shell_exec('echo“输入不正确”); 回显“$output”; endif; $testing=shell_exec('echo“testing”); 回声“$测试”; ?> PHP正在运行,我能够执行一个基本脚本:


我过去在
shell_exec()
方面遇到过问题,倾向于依赖
system()
来封装命令,也可以尝试
而不是
来封装命令。您可能还需要更改调用脚本的方式:

发件人:

要(专门调用python解释器):


我猜相对路径是
/
。PHP进程的当前目录是什么?我建议使用完整路径。我改为完整路径,但仍然不起作用。无论路径如何,“测试”和/或“不正确输入”是否仍会在页面上回响?请勿在生产中使用此代码。您正在将用户提供的数据直接传递给shell。您的服务器可能会被第一个传入的人彻底摧毁
;rm-rf/
通过
$\u POST['cirdiptext']
访问。请理解这一问题,但这将仅对受控用户子集(3)进行内部访问。除此之外,还有更好的方法吗?显然,将输入清理为只接受特定格式会很有用,但是否还有其他东西可以用来代替$u POST?
<?php
    $ipcidr_text = $_POST['cidriptext'];
    $listname_text = $_POST['listname'];

    if !(empty($listname_text):
        shell_exec('/var/www/getStarted -l $ipcidr_text');
        $output0 = shell_exec('echo "List of IP's"');
        echo "<pre>$output0</pre>";

    elseif (isset($_POST['cidrch'])):
        shell_exec('/var/www/getStarted -c $ipcidr_text');
        $output1 = shell_exec('echo "CIDR Range"');
        echo "<pre>$output1</pre>";

    elseif (isset($_POST['singlech'])):
        shell_exec('/var/www/getStarted -s $ipcidr_text');
        $output2 = shell_exec('echo "Single IP"');
        echo "<pre>$output2</pre>";

    else:
        $output = shell_exec('echo "Incorrect input"');
        echo "<pre>$output</pre>"; 

    endif;

    $testing = shell_exec('echo "testing"');
    echo "<pre>$testing</pre>";

?>
<?php
    $output = shell_exec('echo "Incorrect"');
    echo "<pre>$output</pre>";
?>
/var/www/getStarted
/usr/bin/python /var/www/getStarted