I have to delete various files on the server using rm.
I tried using:
shell_exec(escapeshellarg(escapeshellcmd("rm -f ./io_cache/".$prob_id."/*")))
where $prob_id is a number as well as a name of a directory. Commands like ifconfig are working fine. When using the same command with exec it returns error code 127. If I use a variant :
exec("rm ".escapeshellarg(escapeshellcmd("-f ./io_cache/".$prob_id."/*")),$out,$ret)
Then it returns error code 1. shell_exec("pwd") returns /opt/lampp/htdocs/mat and the directory io_cache is present in mat.
I also tried doing the job using a python script. When I call python script without system arguments and deleting some random files the script is running fine.But when I am using something like:
shell_exec(escapeshellarg(escapeshellcmd('./rem.py ').$prob_id))
To pass the directory from where to delete files then also nothing happens. rem.py is in mat.
I am working on Ubuntu and using apache web server
Related
I'm running a CakePHP project under XAMPP (Apache) on Windows 10 Anniversary Update.
Apache is running under my user account.
The app calls several external processes via shell_exec(): ImageMagick, phantomjs execute as expected.
I also want to call a bash script, that in turn calls ImageMagick under Ubuntu bash (installed separately, via apt-get). I've had to adjust all paths into a form that bash can resolve.
bash /mnt/e/Projects/project-name/website/bin/crop_to_aspect.sh 1 1
/mnt/e/Projects/project-name/website/webroot/images/agent_photo/tmp_ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg
/mnt/e/Projects/project-name/website/webroot/images/agent_photo/ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg```
The command fails when called via shell_exec(). The same command, written to CakePHP's log, and then called from a cmd.exe prompt, works perfectly.
Thinking it may have been a path issue, I wrapped the same script in a windows batch file, including the full path to bash. I called the full batch file path, ie:
#echo off
SET aw=%1
SET ah=%2
SET in=%3
SET out=%4
C:\Windows\System32\bash.exe /mnt/e/Projects/project-path/website/bin/crop_to_aspect.sh %aw% %ah% %in% %out%
This script is then called:
E:\Projects\project-path\website\bin\crop_to_aspect.bat 4 3
/mnt/e/Projects/project-path/website/webroot/images/listing_photo/tmp_ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg
/mnt/e/Projects/project-path/website/webroot/images/listing_photo/ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg
Once again, the command executes correctly in cmd.exe but does nothing when run via shell_exec() from the PHP script.
Check if a function is not in the list of functions disabled in php.ini (disable_functions) line
I'm trying to run a ROS shell program on the server through php on Ubuntu 14.04. I have tried using system, exec, shell_exec but nothing happens and I don't get any output. The system call is the following:
echo shell_exec("/opt/ros/indigo/bin/rosrun gazebo_ros spawn_model -database Part_A -gazebo -model Part_A");
What are the limitations of using system or exec to run any shell command through php on a server?
I don't care as much about the output of the command as for its execution. I think the problem has to do with the fact that PHP doesn't have any PATH like shell does so it can't find any applications without specifying the exact location. How can I make PHP se the same PATH shell does?
The problem was that the apache user and the environment in which the bash commands are running are not set up correctly. I followed the instructions from this answer but instead of using "source" I used "." and instead of using the source.bash file I used the source.sh file. I also set all the environment variables that had to do with ros or gazebo using the putenv() function.
I am trying to get the path to certain exe's using the where command in the command prompt on windows.
Here is what i did in command prompt.
where g++
where java
where javac
where python
All of these are giving the correct output of the path in the console window which indicated that I have set the environment variables correctly.
But now When i try to run the commands using the shell_exec() function in PHP, only the call to where java and where python gives the correct output. I was even able to successfully execute a respective test file using these commands through PHP.
But strangely, where g++ and where javac give this error in the browser when run through PHP:
INFO: Could not find files for the given pattern(s).
Also if I get the outputs of these two commands on the console and then copy that into my script to compile a c++ or java file, it works perfect. But the where command returns the above INFO when run through the PHP script.
I am running the server on localhost using XAMPP. Any idea what is missing?
I have a windows server, and I' trying to use scheduled tasks. When I create the job and try to run it through the interface, it says it works, but when I look at the DB it shows me that nothing happend. This is what I placed in the Path to executable file
"D:\Parallels\Plesk\Additional\PleskPHP5\php.exe" -f "D:\inetpub\vhosts\fab-offers.com\httpdocs\cms-sites\vipstore\users\index.php"
Check for:
Is the script working if you run it manualy?
Does php error logs contain anything related to the script?
Does the script contain paths like $_SERVER['DOCUMENT_ROOT'] that it won't have when run not from browser?
I have a shell script that called ant -buildfile /some/where/build.xml
That works fine. When I try to exec('shellScript'); or exec('ant -buildfile /some/where/build.xml'); it will fail. I have tried passthru, system, pcntl_exec, popen, and shell_exec with both the shell script and the command.
The build script uses SVN, and checks out some files. That's where it fails. In the ant script output, I get:
checkoutTrunk:
[svn] started ...
[svn] failed !
When I run the command or the shell script from SSH, everything works fine. Why would being called from a PHP script stop the checkout from working?
After getting nowhere, I changed the command it was trying to execute to 'id'. I found out that PHP was running as a different user than I thought. When I SSH as that user, I get an error when I run the command due to not having access to write to a directory. Once I changed permissions on those directories, I could then run the command as the PHP user from SSH. After I could do that, it also worked from the PHP script.