There is a website with a button, cliking the button should lunch a bash script that suppose to unmount a directory. The button calls functions.inc php script with this function:
function sftmz_release_s3test_connections($bucket_name){
if($bucket_name == 's3test'){
drupal_set_message('Check mount status ! - released?');
$cmd = '/var/www/html/company/sites/default/modules/rp_minisite/admin/script.sh';
exec($cmd);
}
}
My problem is: When im in the shell and running the command:
/var/www/html/company/sites/default/modules/rp_minisite/admin/script.sh
It works fine.
When I click the button, the test appears, but it does not run the script. How can i view logs ? Can i print logs to shell ? i cant since its being activated using a button on html...
I assume this is permission issues?
Try getting some more info about what actually happens when you call exec:
exec($cmd, $return, $status);
echo '<pre>';
var_dump($return);//is an array, containing the commands output
echo '</pre>';
if ($status === 0)
{//normally, if a cmd exits with 0, all is well
echo 'Command executed';
}
If there is something funny going on, you might want to check if your script is relying on environment variables/aliases and the like being set. Perhaps you'll have to load a .profile file for the script to work.
Here you can see how to do this
Have you checked the return value of the exec() function ? See the doc for more info.
Try using the other arguments of the exec command..
Related
I have a problem when i try to run this exec statement. The exec wont start the php shell file as i want it too.
I've tried using shell_exec but that wont work either. And when i try to echo out the returning array and var i get the var to "1" and an empty array.
Here is my code I'm trying to execute:
<?php
$user = $_GET['u'];
session_start();
if ($_SESSION['user'] === $user) {
$sID = $_GET['si'];
exec('php C:\\xampp\\htdocs\\r\\pages\\create-csgo-server3.php');
echo 'Server is being created.<br>';
} else {
echo 'Permission denied.';
}
?>
It says "Server is being created." but it wont run the exec correctly.
php C:\xampp\htdocs\r\pages\create-csgo-server3.php
I tried putting this over into the cmd and it worked correctly.
Thank you for taking your time!
I'm sure there is a duplicate, but while I'm searching; the webserver user (user that runs Apache or IIS, etc.) doesn't have the path to php.exe in its path environment variable, but you must as it works for your user in a terminal. Always use full paths:
exec('C:/path/to/php C:/xampp/htdocs/r/pages/create-csgo-server3.php');
I am have a PHP script called process_item.php that can be run from terminal. I want to create a web script that can run the same file using exec(). My web script(process_item_online.php) looks like below:
ini_set("display_errors",true);
error_reporting(E_ALL);
$item = $_GET['item'];
echo "Received request for item $item<br>";
$cmd = "/usr/bin/php /var/www/html/process_item.php $item";
exec($cmd);
echo "Processed using command - $cmd";
The script process_item.php has 777 permissions. When I run the above script in browser, I get both these lines printed correctly:
Received request for item 10023444AJK
Executed command - /usr/bin/php /var/www/html/process_item.php 10023444AJK
However nothing else happens. As in, the database is not updated, the logs are not written etc. I do not get any error on the browser either. I am sure this is a permission issue since it works fine from the terminal. Can anyone give me any pointers on how I can make this work from the browser?
I am using WAMP server on my system to execute php scripts.
I want to execute a script test.php from my main script main.php.
For that I am using exec function like this exec('php test.php');. In test.php I have given one echo statement.
But when I run my main.php script from the browser I am not able to see output of test.php script.
What am I doing wrong ? please suggest.
You have to give the proper path of php.exe
exec("c:\wamp\<where ever you exe is>/php.exe test.php");
so it has to be a proper path
use this command
echo exec('php test.php', $output); //this will print your echo statement.
print_r($output);
I'm trying to run the following command from a PHP file in a web browser:
exec('festival --tts /var/www/test.txt &');
Unfortunately, nothing happens. I thought of trying 'echo' but there is nothing to return to see if the command is working. I set permissions for test.txt to 777. I also ran the command in a shell and it works just fine - just not when submitted by a PHP script. What am I doing wrong?
Provide the full path to the festival binary, you can find it out on the console with which festival command, then use it in your exec call, like this:
exec('/usr/bin/festival --tts /var/www/test.txt &');
Update:
You need to make sure the folder where you are creating the file has write permission for the user running php which usually is www-data on debian based distros.
If I understand correctly what you're trying to do, you aren't returning the input. The syntax for this is:
exec('command', $output);
where $output is the variable in which the script's output will be stored. Oddly, this output will be returned as an array, so don't forget to implode() it when you're done if you're expecting a string.
Does the festival program print any output? If so, try capturing that. Also check the return value.
exec('/usr/bin/festival --tts /var/www/test.txt &', $output, $return);
Dump the output array, like so:
var_dump($output);
Any non-zero return value usually indicates an error:
echo $return;
I have a webpage on a linux NAS, with webserver and php running.
I want to start a script from de server, to write data to a database.
When i am on the new69.php (the website in question)
I have the
for example :
$uptime = exec('uptime');echo $uptime;
(and this works)
So i have a connection.
Then i do with a if statement:
if (isset($_POST['verzenden'])) {
$output1 = exec('whoami');
exec('/share/MD0_DATA/Qweb/sqlite/AllesNaardDB.sh');
} else {
echo "Nog lekker niets gedaan.";
Whoami in the is statememt gives the username "httpdusr",
So the if statement gets reached and works.
Now the exec statement when i do:
It has to execute the AllesNaardDB.sh
which contains:
cd /share/MD0_DATA/Qweb/sqlite
echo "Wasmachine"
python2.6 wasm_util_sql.py [param]
echo "alles gegeven"
exit 0
Nothing is shown or done.
But when i do:
$output = exec('/share/MD0_DATA/Qweb/AllesNaardDB.sh');
echo "<pre> $output </pre>";
I get the als line of the script in the variable $output,
"alles gegeven".
At first i tought that it could be something to do with the rights.
So i (switched user with) su to "httpdusr" and script in putty gets executed fine.
I also made another script ff.sh with "ls -l" to execute and everything works.
Also i treid
passthru(),
system(),
shell_exec.
The only improvements are that with system() and passthru(), the "echo "Wasmachine""
appeared on te website.
I don't get why the python jobs don't get started ?
I worked a little further, but could it be that there are some sqlite3 command which are user dependent ?
Like that i could execute some write action to the database as admin, but not as the httpdusr ?
try adding #!/bin/sh to the top of the script and make sure it's chmod a+x.
It is a prblem with a path in the python script, which is writing to the database.
It uses a different path when it is started from the webpage (MD0_DATA/Qweb/) then wen it is started from the shell script (MD0_DATA/Qweb/sqlite)
*i dit not solvend the problem yet, but understand it.
Everybody thanks for the effort.