简体   繁体   English

如何从PHP调用Shell脚本

[英]How to call the shell script from php

i am trying to call the shell script using php. 我试图使用php调用shell脚本。

Here i have one ajax code that gets the that gets the drop down value & send the values to another php page( deleteslide.php ). 在这里,我有一个ajax代码,该代码获得下拉值并将这些值发送到另一个php页面( deleteslide.php )。

The deleteslide.php gets the values from this page and calls the delete-slide.sh script with the parameters with values that has got from main page. deleteslide.php从此页面获取值,并使用带有从deleteslide.php获取的值的参数调用delete-slide.sh脚本。

But when i run the code it is not calling the script... 但是当我运行代码时,它没有调用脚本...

How to solve this problem 如何解决这个问题呢

here is what i have done: 这是我所做的:

main page(index.php) 主页(index.php)

AJAX Code: AJAX代码:

$("#deleteslide").click(function()
    {
        var prjid=document.getElementById("project-list").value;
        var unitid=document.getElementById("unit-list").value;
        var slidid=document.getElementById("slide-list").value;
           var d ='deleteslide.php?projectId='+prjid+'&unitNo='+unitid+'&slideNo='+slidid;
            $.ajax({                   
        url:d,                                           
        success:function(output)
        {              
            alert(output);              
        }           
    });
    });

deleteslide.php code: deleteslide.php代码:

<?php
$prtId =$_GET["projectId"];
$utNo=$_GET["unitNo"];
$sdeNo=$_GET["slideNo"];
 $c='/var/www/createslides/gen-json-data/delete-slide.sh '.$prtId.' '.$utNo.' '.$sdeNo;
 //print("$c");
$output=shell_exec($c );
print("$output"); 
?>

Here deleteslide.php is calling the delete-slide.sh script, but the script is not running.... 在这里,deleteslide.php正在调用delete-slide.sh脚本,但是该脚本未运行。

What could be the problem?? 可能是什么问题呢??

How can i solve this?? 我该如何解决?

May be your script don't have execution permission:- 可能是您的脚本没有执行权限:-

1)Either give execution permission to your sctipt:- linux_shell> chmod +x /var/www/createslides/gen-json-data/delete-slide.sh 1)都可以给您的sctipt授予执行权限:-linux_shell> chmod + x /var/www/createslides/gen-json-data/delete-slide.sh

or 要么

2) Use "sh" to run your script:- 2)使用“ sh”运行脚本:

$c=' sh /var/www/createslides/gen-json-data/delete-slide.sh '.$prtId.' $ c =' sh /var/www/createslides/gen-json-data/delete-slide.sh'。$ prtId。' '.$utNo.' '。$ utNo。' '.$sdeNo; '。$ sdeNo;

Note:- When you test shell script in linux shell, then it execute as logged in users permission but when you run it through web then it run as apache users permission, so apache should have permission to execute that script... 注意:-当您在linux shell中测试shell脚本时,它会以登录用户权限执行,但是当您通过网络运行它时,它将以apache用户权限运行,因此apache应该具有执行该脚本的权限...

Try adding error_reporting(-1); 尝试添加error_reporting(-1); Could be shell_exec is disabled. 可能是禁用了shell_exec

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM