0

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

2
  • are the permissions set right? does it work if you run the script manually? does the Apache (or whatever you're using) user have permission to run scripts? Commented Nov 18, 2013 at 12:09
  • @Spokey Yes if i run the script manually with parameters it is running properly. Commented Nov 18, 2013 at 12:10

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.