PHP - Help With Shell_exec
Hi Guys
I cant seem to get unzip to work via php shell_exec this is what I have: Code: [Select] $rworld = $_GET['restore']; $connect->call('remotetoolkit.stopServer',Array()); sleep(12); $nrworld = substr($rworld, 0,-15); $sftp = new Net_SFTP($host); $sftp->login($root_user, $root_pass); $sftp->delete('/root/minecraft/'.$nrworld.'/', true); echo shell_exec("unzip -jo /root/minecraft/saves/$rworld -d /root/minecraft/$nrworld"); sleep(5); $connect->call('remotetoolkit.startServer',Array()); Nothing is returned, it doesn't echo and the command is not executed. If I execute via terminal and change the $variables to the actual names it works fine, and I can ls with shell_exec successfully? Any ideas? Similar TutorialsGood Friday to everyone! I am writing some PHP code to find certain files and the search the files for a certain string. For example, this is what I have. This works in a LINUX shell environment, yet I need to have it work in PHP since the GUI is web based. Can anyone help? Thanks! Mike Code: [Select] <?php $output = shell_exec('find /sync/www/html/ohx/products/MEMNPWOHX* -type f -exec grep "HEAT ADVISORY IN EFFECT" /dev/null {} \;'); echo "<pre>$output</pre>"; ?> Hi im Art, Im trying to make use of Shell_exec() function to execute gammu(smsgateway for linux<CLI>) to text a message using my php page. This is my actual code: <html> <form method="POST"> Message: <textarea name=Message></textarea> Number: <input type=Text name=Number> <Input type=Submit name=Send value=Send> </form> </html> <?php extract($_POST); if (isset($Send)){ $output = shell_exec("pwd"); echo $output."<br>"; $cmd="gammu --identify"; echo $cmd."<br>"; $output = shell_exec($cmd); echo $output; $cmd="echo '".$Message."'|gammu sendsms TEXT ".$Number; echo $cmd."<br>"; $output = shell_exec($cmd); echo $output; } ?> But this is the error: /opt/lampp/htdocs gammu --identify Error opening device, you don't have permissions. echo 'Hi There'|gammu sendsms TEXT +639270000000 Error opening device, you don't have permissions. PS: It works well if just issue the command echo 'Hi There'|gammu sendsms TEXT +639270000000 on my terminal but i dont know why it doesnt work for php, and another thing, i wasnt using any sudo commands on shell i just type the command directly, hope someone can help me out thanks I'm trying to call a command using shell_exec by doing the following- Quote shell_exec("C:\\myprogram.exe -t")or die('error'); but that doesn't work, as it returns 'error'. The command "C:\\myprogram.exe -t" works perfect when i call it myself using the cmd.exe but not when i try using it in php with shell_exec. Safe mode is off and i'm using apache as my php webserver. Does anyone know what the problem is here and if not then is there any other ways of executing myprogram.exe in php? When i try to do a shell_exec from my script the script does not work. But when i put the same thing in a .bat file and execute that from PHP it wroks. Can anyone help me shell_exec('xcopy C:\xampp\htdocs\test\backup\test.zip "\\fileserver\KT_backup\aback\" /i') This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=344940.0 Hi guys, I'm running the following code: Code: [Select] $result = shell_exec("su user; scp /path/to/file/text.txt user@domain:/path/to/file/text.txt"); Now, the file get's transferred correctly. However, I need to put in place a check to check if the transfer was successful. $result seems to return the same whether the transfer was successful or not. I want to send an email to state whether the file transfer was successful so what do I need to do to check this? Thanks! Hello all, I am using a shell_exec command like the one below: $output = shell_exec('c:\powershell\powershell.exe get-service'); echo($output); However, when launching the page, the browser will hang with the hour-glass. If i end the powershell.exe process on the web server via task manager, the browser then returns the expected output. Any idea why this is? Other commands, like ipconfig return the correct output and the browser displays "Done" in the bottom left. Any help appreciated. Andrew In the browser when I open the file I need to see the output of the ifconfig linux command on the server. This is the index.php <? $iplist = shell_exec("ifconfig"); print "<pre>$iplist</pre>"; ?> but when I open the index.php in a browser I can see only the first couple of lines, nothing more. Can someone help me what to do? The strange thing is when I run the index.php from the command line with "php index.html" it shows the correct result. Any help..? Thanks, I am using shell_exec, and it runs a ping on a server, is there any way to flush the buffer of the shell_exec as the data is getting written to the buffer? Because I sometimes ping a site 10 times and nothing get written until the function finishes, so is there anyway to write out the output as soon as it is available? btw, this isn't only for doing a ping it is for other things as well. NB: oh yeah, the specs: PHP 5.5.9-1ubuntu4.4 Server version: Apache/2.4.7 Ubuntu 14.04-4
OK, this is driving me completely nuts.
Yes, the first problem is, I'm modifying someone else' code, so I'm trying to cludge this, but I don't have the time resources to write the entire application, at least not at this prototype stage.
That said, start_exec() works wonderfully in a standalone, test script, so there's nothing wrong with the server or php mods / version.
The scenario, on clicking an href or button, I want a script to run (it loads files from a remote sftp and also wgets from another server). One would think this isn't much of a problem, so here's where it becomes crazy making.
The code I'm working with is generating the html with print() in the form of print "<html>";
I've tried the usual examples for doing this function, but none of them are using embedded php in embedded html.
So this:
print"<tr><td class=leftsub><div width=100% class=info id=tasks> <a href='windows.php?pull=true'><img src=images/explore.gif width=16 height=16> <u>Pull files from server</u></a><br>does not invoke this: if ($_GET['pull']) { # This code will run if ?pull=true is set. shell_exec('pull.sh'); }Which is all in the local function. And this doesn't work either: print "<img src=images/extract.gif onClick='shell_exec('./pull.sh')' class=button title='Pull files'>";Nor does this: print ("<form method='post'><p><button name='button'>Run Perl</button></p></form>");seem to call this: if (isset($_POST['button'])) shell_exec('./pull.sh');There are other ways I could perform the same, even just a cron that pulls and pushes on some regular interval, of couse which is checking to see if the files are open before pulling or pushing, but I'd rather it be on demand. Am I just going to drive myself nuts without re-writing the entire code? Should I rather just have the requests call a different php script which then inline shell_exec()'s the shell script? Any insight and feedback is very much appreciated. Cheers, Kevin Edited by krattai, 21 September 2014 - 01:43 PM. Debian 5 PHP 5.2.6-1 This script works: <? $output = shell_exec('ls -lart'); echo "<pre>$output</pre>"; ?> This script doesn't work: <? $vars=unserialize(file_get_contents("file.txt")); $output = shell_exec('ls -lart'); echo "<pre>$output</pre>"; ?> I get error: Quote Warning: shell_exec(): Unable to execute 'ls -lart' or Warning: system(): Unable to fork [ls -lart] If file.txt has size 500k, the script works without errors. But my file file.txt has size 30M. Help. if(isset($_POST['clearflags'])){ $output = shell_exec('php clearflags.php'); } The above works fine on my local development server running Debian 10, PHP 7.4 and Apache 2.4.25. clearflags.php is a script that clears various fields in a MySQL database so it's easy to determine if it properly ran or not. On my hosted server however (Bluehost), clearflags.php is never executed. My hosting service swears that SAFE MODE is not on in PHP (which is also Version 7.4). If I call from the command line (php clearflags.php), it runs fine. $output on the hosted server is "Content-type: text/html; charset=UTF-8 " but nothing on my local server where the script is called and runs OK. No entry appears in the error log about this I've also tried using exec() with the same failed result Running phpinfo() on the hosted server shows that disabled_functions are "no value" Thoughts? Edited October 11, 2020 by KenHorse |