This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php shell_exec() vs exec()
How do I run a linux command from a PHP script? I'm running Linux Debian and PHP5. I want to be able to issue a wget command to the console.
An example of what I'm looking for is something like this:
phpFunction ("wget http://www.example.com/image.jpg /folder");
echo "done";
Also would I be able to echo the output of that function?
Use exec to run any command. Be careful not to exec any user input though, as it can severely compromise your server.
Also, note that most shared servers block off the exec function so you won't be able to use it.
Finally, as a shorthand, you can wrap the command you want to exec in backticks.
You can do what you want with the following code :
system(command);
See http://php.net/system
You can execute linux commands within a php script - all you have to do is put the command line in brackits (`).
And also concentrate on exec() , this and shell_exec() ..
you can use
exec
shell_exec
http://php.net/manual/en/function.shell-exec.php
Related
This question already has an answer here:
Convert multiple SFTP command lines to a single line command line
(1 answer)
Closed 4 years ago.
Is it possible to use SFTP linux command, using php exec() or system() function?
I try this:
exec('sftp '.$user.'#'.$server.' && '.$pass.' && get '.$path1.' '.$path2.');
but it doesnt work. Guess because of login at least)
Also tried to split execs, still its useless:
exec('sftp root#'.$server);
exec($pass);
exec('get '.$path1.' '.$path2);
maybe there is any inline command or another syntaxis for this?
And yes, i want to use SFTP, no i dont wanna use libraries.
Also if there is some way to make it work with special bash or etc file, that i can run with exec() it would be nice too.
The solution is:
system('sshpass -p '.$pass.' sftp -o StrictHostKeyChecking=no root#'.$server.':'.$path.' '.$path, $D);
It might be kind of a nooby question but ...
How can I possibly run a php command like php /path/to/script.php on a hosted web-server?
I have no access via SSH or something.
You can check if the program execution commands like exec() have been disabled on the server side using:
function execEnabled()
{
$arrDisabled = explode(',', ini_get('disable_functions'));
return (!in_array('exec', $arrDisabled));
}
A list of all system execution commands can be found here:
http://us.php.net/exec
If exec(), passthru() etc. have been disabled, there is no way to execute shell commands.
As Christian Ciupponi asked, why would you execute a PHP script using shell command? You could simply include the file to run it if file access to the script is permitted.
Have a look at this function, maybe it will help: http://it1.php.net/function.exec
By the way why can't you just visit the page you need? In this way the script will run
EDIT:
How to use the exec function:
The exec function allow you tu execute an external program when you do not have access to an ssh consolle. (note that this function can be disabled by the sysadmin )
For example you can use:
$whoami = exec('whoami');
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Executing linux commands with PHP
I have a PHP file that creates an .xfdf file I am wondering if PHP has a way of executing a command like you would type into the terminal window? I have to run the following command when after the .xfdf file is created to generate the .pdf file
pdftk /var/www/pdf/TimeCard.pdf fill_form /var/www/pdf/results/Brandon_01_23_13.xfdf output /var/www/pdf/results/testNew.pdf flatten
The command would need to be able to accept a PHP variable so its customized for the user. Is there an easy way to do this?
Yes, you can use exec(), pcntl_exec(), system().
$command = 'pdftk /var/www/pdf/TimeCard.pdf fill_form /var/www/pdf/results/Brandon_01_23_13.xfdf output /var/www/pdf/results/testNew.pdf flatten';
exec($command);
Be very careful when using these commands, they are very useful/powerful, but because of this a hacker could potentially gain access to your whole server through it (depending on permissions, but it's more than enough to compromise your site).
If you need to send user uploaded file names/text, check them to the blood (for example check if the file path is in the proper place, and not ../../../something.pdf, check MIME types and extensions).
Yes, you can use:
system
exec
passthru
Depending on your exact requirements, you can use exec(), system() or shell_exec()
Use the system() or eval() functions.
But make sure the user can not inject arbitrary commands!
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Call Python From PHP And Get Return Code
probably a very stupid question
I have a python module lets say hi.py which have the following
print "hi"
now I want to execute this file from php
<?php
#code here
?>
So how do I call that python file from php.
Thanks
Use the exec function to invoke Python.
Example:
$output = array();
exec("python hi.py", $output);
var_dump( $output);
There are other commands for executing commands on the machine PHP is running on, see the docs.
you can call php exec function and call
python -c "print 'hi'"
or if you have larger module you can use
-m mod : run library module as a script (terminates option list)
so in the end I'd use
exec("python -m hi");
and don't forget to configure PYTHON_PATH on your server if needed
be careful doing this kind of stuff
Occasionally my media server goes down and I'm wondering if it's possible to start it remotely using php to check the port and if it's not running invoke cron (or some other way) to run a shell command. Is this possible because this is not a strong area for me. Here's the process I use with PuTTy.
login to shell
cd to source/red5/dist
screen
./red5.sh
CTRL-A then D to detach
logout
Simplest thing is to write a shell script. And then login to remote console via PHP.
shell_exec: execute a shell command and returns the output as string.
exec: just executes an external program
A simple way to achieve what you want is to run this in screen:
while /bin/true ; do ./red5.sh ; done
If you can write a shell script that does what you need, then PHP's has exec(), system() and passthru() for you.
PHP actually has a special operator for executing shell commands, the backtick:
`cd source/red5/dist`
will go to the specified directory. (But I don't know much about shell, so I can't implement you the whole thing.)
If you need much control over the execution (I don't know whether you need here) use proc_open.
you can use corn job on php and put all command on .sh file and run like this
59 11 * * 1,2,3,4,5 root command file.sh?token
something like this ,it will be save
There is more than one good answer here, but you should opt for executing the init script for red5 instead of the .sh or .bat. There are pre-made init scripts here: http://code.google.com/p/bigbluebutton/downloads/detail?name=red5&can=2&q= and here: http://www.videowhisper.com/forum.php?ftid=48&t=init-file-red5-linux-installations-red5-linux-init.d-chkconfig