简体   繁体   中英

How to call the shell script from php

i am trying to call the shell script using php.

Here i have one ajax code that gets the that gets the drop down value & send the values to another php page( 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.

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)

AJAX Code:

$("#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:

<?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....

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

or

2) Use "sh" to run your script:-

$c=' sh /var/www/createslides/gen-json-data/delete-slide.sh '.$prtId.' '.$utNo.' '.$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...

Try adding error_reporting(-1); Could be shell_exec is disabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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