Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





System/shell/exec/etc


I've got PHP 5.1.6, Apache 2.2.2, on Fedora 5. Everything is great except that when I use an of the external launching commands, persistent apps dont stay open. I have a simple shell script set up to load an app, and I have it write a PID file. Immediately after calling exec (milliseconds later) the PID is alive. However, within a few more milliseconds it seems to close.

I've made sure that the apache uid/gid have full access to the script and the apps it calls. When sudo'ing manualy in a shell with the apache uid, the script works flawlessly and loads the program, and stays open, as it should. I've verified that the app loads under the uid 'apache' with ps. When running it through PHP, it seems to close almost immediately after succeeding.

Is there some fundamental issue with how this works that I'm missing? I can't seem to get any real errors out of php, apache, or even the shell when redirected to a file. Should I try PHP4? Is PHP5 buggy with this kind of thing? I even tried running 'at' to schedule the script (so that it'd be invoked by at instead of the shell itself) but that failed, silently, as well.




View Complete Forum Thread with Replies

Related Forum Messages:
Shell Exec
I want to call an external console program and get its output, that's what I did:

execute.php :
<?php
$output = shell_exec('F:/Apache2/htdocs/misc/excecute.exe 8 6');
echo "<pre>$output</pre>";
?>

execute.exe: is a console program which multiple argv[1] with argv[2] and printf the result, I have tested execute.exe in Dos mode works perfectly, but when I run the php script, I get no output.

View Replies !
Exec() Function And Shell Scripts
I have a shell script written that basically grabs a selected .jpg or .png image file and wraps it as an .swf file for use in a dynamic Flash site. My question is this: What are the limitations of the exec() or system() commands? I can get them to work just fine with common linux commands(ie. ls -l, pwd, etc.), but it won't run these sort of commands:
./thisisascirptname
or
sh wrapper.sh

I get no results with these and yet when I perform the same operation on the command line by hand, it works just fine. This is the script I'm using to test it, by the way.

$lastline = exec("sh wrapper.sh", $all_output, $return_value);

print("<b>Last Line:</b><br>$lastline <p>
");

print("<b>All Output:</b><br>
");
for($index = 0; $index < count($all_output); $index++)
{
print("$all_output[$index] <br>
");
}

print("<br><br>
");

print("Return Value: $return_value<br>
");

The "ls" and other similar functions all return properly. I can't figure this out and it's driving me nuts. Any help?

View Replies !
Shell Symbols And Exec Problem
I have a problem running following shell command from php exec or
system call:
exec("/bin/cat $(/bin/cat list.txt) > concatenated.txt"). This works
when i run it directly from the shell as user nobody (apache user), so
its not a path/permissions problem.
Basically list.txt contains a list of filenames, which are to be read
and concatenated into one big file (concatenated.txt).
I have even tried writing a shell script, wrapping this command, and
tried running it, but still no result. The script either way just
writes an empty concatenated.txt.

View Replies !
ProgressBar For A Shell Exec Command
I am executing a shell command through php

$command = "some mathematical calculations":

$output = exec($command);

The $output takes approximately 10 - 40 sec for its execution every time. I wanted to show a progress bar proportionate to the time of execution. Code:

View Replies !
Executing Multiple Shell Commands Via One Exec()-call
I wrote a PHP shell script under Linux which puts all existing
[E]PS-Files within a directory into a list and should then start a
single Ghostview window for each file. Sounds simple, but it's not:

The following code provides for about half of the functionality I
wanted:

==============code starts
$bla = array();
foreach ($filelist as $file)
{
$bla[] = fopen("./trash/".$file.".tmp", "w");
exec ("gv ".$file." &", $bla);
}
===============code ends

Here, all files are opened one after another. The next file opens only
after closing the current one. Actually I don't know whether the
redirection of the output towards .tmp-files complies with the
intended purpose of the redirection. The PHP manual states that when
starting programs in background, the output would have to be
redirected to a stream or file, otherwise PHP would continue to run
until the respective program is terminated (which I really wouldn't
care about at all, if it did so...).

Then I thought about writing the line I would type manually for
opening all ps-files ('gv bla1.ps & ; gv bla2.ps&; ...') into a string
and then executing that string:

===============code starts
$command="";
$bla = fopen("./trash/tmp", "w");
foreach ($filelist as $i => $file)
{
if ($i < count($filelist) - 1)
{
$command = $command."gv $file & ; ";
}
else
{
$command = $command."gv $file &";
}
}
exec ($command, $bla);
===============code ends

sadly I get an error message from the shell:
================ error message starts
sh: -c: line 1: syntax error near unexpected token `;'
sh: -c: line 1: `gv uges_Boden.ps & ; gv ux_Boden.ps & ; gv
uy_Boden.ps &'
================ error message ends

View Replies !
System() And A Shell Script
Trying to get a shell script to execute. Works fine from the console, not from php. Script is in the same directory as the page. Any ideas?

<?php

$test = system('sh stop_music.sh', $retval);
echo $test;
echo $retval;

?>

View Replies !
PHP System() And Exec()
Background: I am trying to execute a binary on the server located in the current directory where the php script is being run. The server is a linux (debian based). I am having trouble getting php to execute the binary properly, below is my code. Code:

View Replies !
System() And Exec()
If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.

I have tried numerous time by redirecting to a file or other stream to free up a php web page that called a perl script for example, but the php script always hangs...has anyone had any luck freeing up a calling php script from a process, or program that it launched in the background? Code:

View Replies !
Exec(), System()
I write very, very simple script who call external program. The script is run on Linux Slackware, Apache/1.3.37 (Unix) mod_ssl/2.8.28 OpenSSL/0.9.8b PHP/4.4.4 here is my script:

<?php
echo exec('ls');
?>
this work properly.

but if i write:

<?php
echo exec('xine'); //xine is a multimedia player
?>

View Replies !
Bug In System And Exec Commands
If PHP is running via a web server, and mutiple system
calls are made within the script to another script,
hundreds of processes are created. Here is an example:

Script 1:
<?php
for ($i=1; $i<=5; $i++) {
system("php script2.php");
}
?>

Script 2:
<?php
exit;
?>

The effect is the same (and more difficult to stop) when
the system calls are made in the background. e.g.

system("php script2.php >>/dev/null 2>>/dev/null &");
system("php script2.php >/dev/null 2>&1");

I have even tried calling a shell script, which in turn
calls the second PHP script (both in the background), but
it still causes lots of processes.

The "exec" command is also affected.

At first, I thought this was a problem with either Zeus web
server of Fast CGI, but I have since tried it with Apache
and normal CGI with the same effect.

Does anyone have any idea why this happens and whether there is any way to prevent it? I have posted a bug report to bugs.php.net (ID 14997), but so far to no avail.

View Replies !
System() Or Exec() And Permissions
I'm trying to run a command (mogrify) that requires that I'm logged in as root, or at least I think this is the case. How can I do this?

View Replies !
Exec() And System() Problems
I am trying to use php's exec() or system() to execute a shell script that I wrote.

exec and system() work fine with a simple command like ls, but nothing happens when I point it at the shell script.

The shell script works fine from my shell login. Can't figure out what tho problem is. Is php just incapable of running shell scripts?

View Replies !
Using Passthru(), Exec(), System() Etc.
I have an executable that runs as expected from a command prompt but seems to do nothing when I try to run it from php, using passthru(), exec(), etc.

View Replies !
Exec(), System() And Win 2003
I have searched high and low for the past 2 days for an answer to my problem. I have found a few references, but nothing has helped me. My problem is this: I am trying to ping a remote server from a PHP script in IE 6.0. When I load the page, the cmd.exe loads on the server and takes up all my CPU. I have to manually stop the process for it to go away.

My setup is this:
Windows 2003 Server
PHP 5.0.1

I have tried
- giving my system32cmd.exe full IUSR_%machinename% rights
- moved the cmd.exe to the script folder, to the PHP folder

And about a million other things that I can't remember =(. I have tried multiple functions, written in mulitple ways and the outcome is always the same. when the cmd.exe is opened it hangs on the 2003 server.

View Replies !
Use Exec() In PHP 5.2 On A Windows XP Pro System
I'm trying to use exec() in PHP 5.2 on a Windows XP Pro system. What I'm trying to do is use it to tell an already running program what to.

For example:
X:pathprogram.exe /something
or
X:pathprogram.exe /something_else

If I do the command through the command line, it works, but so far I have been unsuccessful in PHP. Usually it PHP just hangs, and give no error message, and does nothing to the program.

View Replies !
Problem Using System/exec Function.
I am faced with strange problem. Basically I want to make a script which would take mysql back up for me. I have come up with following. [ basically code is borrowed from some other place ]
PHP Code:

View Replies !
Using System/exec, How To Backup Database?
system("mysqldump --opt myDatabase > backup.sql");

here are my problems,

i don't think it works on the webserver. next, where exactly the file, backup.sql be place if it does succeed.

i believe we just can't execute commands on the webserver can we?

i also tried using the sql query BACKUP TABLE ... TO .. but i'm guessing the problem lies with the TO... how do i know what directory shall i place it therE?

for instance, my pages are placed in,

home/myname/public_html/...

i tried to put
home/myname/public_html/backup in the TO but nothing happens.

View Replies !
Exec(), System(), Shell_exec(), Etc + Nmap
i'm trying to create a script that executes nmap from my server, then displays the output.

i've tried:

$output = passthru('nmap -v -A'.' $ip');
$output = shell_exec('nmap -v -A'.' $ip');
system('nmap -v -A'.' $ip');

the problem i'm having is that using the above methods i only get the first line of output, ie.

Starting Nmap 4.20 ( http://insecure.org ) at 2007-08-31 21:46 CST

and nothing else. i've managed to find a way around it by sending the nmap output to a textfile, the using file_get_contents() to pull the data back in:

exec('nmap -v -A '.$ip.' > /usr/local/www/apache22/data/nmap/'.$ip.'.html');    
$file = "/usr/local/www/apache22/data/nmap/$ip.html";
$result = file_get_contents($file);
echo "(pre)$result(/pre)";

that works perfectly, but i'd rather not be writing anything to the drive. i guess the problem might be that nmap takes about 5-10 seconds to do its scan, and for some reason php doesn't want to wait that long, i really have no idea. can it be made to work without needing to write to files?

and for the curious minds, i'm not doing anything dodgy, i just wanted an online tool i could access from any computer to test networks i support .

View Replies !
System/exec Not Working In Browser
In two files, and I serve foo.php then I notice If I use commandline execution i.e. php foo.php then foo.txt is touched/created all right. i.e. system command is executed as expectedBut If I use browser then I notice that the shell command in config.php is *not* executedAny ideas as to why this might be happening? Code:

View Replies !
Command Window - Exec/system
I'm in the process of developing a script in Windows where I need to use exec/system. Whenever I execute either, Windows spawns a command window which automatically sappears. Is there a clean way to force Windows to NOT display the command window?

I've seen this discussed a few times previously, but, none of the
solutions seem to be working (tried both exec and system; tried using
cmd /c, tried using start /B, etc.)



View Replies !
Exec, Shell_exec, System, And Passthru Not Working At All
Can't get these commands to work! The following page simply doesn't
finish loading ( Waiting... Opening... :-( )

<?php echo system("dir"); ?>

The same for <?php echo exec("dir"); ?> or <?php echo
shell_exec("dir"); ?>, etc...

I'm running Apache 2.0.55 & PHP 5.0.5 with Zend Optimizer v2.5.10 on
windows XP SP2.

View Replies !
Exec And System Commands Blocked By Host
I've got this code, its the simpliest example I could make. It works perfectly on my windows xp/apache/php box, but doesn't do anything on a commercial website host. The actual code should use gzip to compress a folder but that doesn't work either.

Anyone know the reason why they would be blocking these commands? I suspect the problems with commonly used php apps like phpBB to be the real reason.

<?
exec("ping 127.0.0.1 > test.txt") or die();
// get contents of a file into a string
$filename = "test.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));

fclose ($fd);

echo $contents;

?>

View Replies !
Alternates To System() And Exec() In Order To Use ImageMagik?
My Web host apepars to not allow exec() and system(), as a line in my script:

system("convert -scale 100x100 $uploadfile $toimage");

gives the error:

"Warning: system() has been disabled for security reasons"

Is there some other way to use ImageMagik (or is it GhostScript?)'s
"convert" command in PHP that may be safer and generally allowed by Web
hosts?

View Replies !
Exec - Create An Executable That Return The System Drives
I need some help about exec command. I have create an executable that return the System Drives. It is based on DOS and does not need any parameter.

I have create my php script that executes the executable i've create and the source code is the following: ...

View Replies !
Running An .exe File Using Exec() Or System(), Unable To Fork Error
I have a problem with running an .exe file using exec() or system() I have downloaded a file called ffmpeg.exe for converting movie clips. I can use the program thourg the command line in windows (cmd), but I'm not able to have PHP run the file. First PHP gave be an "unable to fork" error. But then I gave users access to the cmd.exe file and solved that problem. So now is no problem running for example exec("dir");

View Replies !
System(), Exec(), Shell_exec(), But "Permission Denied"
I want to execute the php script via web server to run linux command. I try to use system(), exec(), shell_exec(), but the system show me "Permission Denied". i have set the file permission by using chmod 777 file.php .

View Replies !
Warning: Ftp_exec() [function.ftp-exec]: SITE EXEC Is An Unknown Extension
This is kind of a part II to a question a posted earlier about exec and shell_exec not working.

I'm trying to use ftp_exec to execute some simple command:

$conn_id = ftp_connect("$server") or die ("Cannot initiate connection to host");
ftp_login($conn_id, "$username", "$userpass") or die("Cannot login");
$command = 'cd..'
if (ftp_exec($conn_id, $command)) {
   echo "$command executed successfully";
} else {
   echo "could not execute $command";
}
ftp_close($conn_id);


I'm getting the following error:

Warning: ftp_exec() [function.ftp-exec]: SITE EXEC is an unknown extension in /home/urieilam/public_html/work/video/test1.1.php on line 21
could not execute cd..

Have tried other commands as well, get the same. Could this be a security issue or something to do with p Safe Mode? I don't know much about commands, shell, etc..

View Replies !
Warning: Exec() [function.exec]:
I'm using PHP Version 5.0.4 in IIS5, Window 2003. When I execute my script, it prompt me the following error :

Warning: exec() [function.exec]: Unable to fork [ping 10.8.1.70] in c:Inetpubwwwrootswitch.php on line 62
Below is my script :

<?php
$line1 = exec("ping 10.8.1.70", $output);
exit;
?>

View Replies !
How To Run A .php From The Shell.
how to run a .php from the shell. I'm running debian, with Apache-ssl which is compiled with mod_php4. PHP for web sites works great. However, to run a php script from the shell, do I need to install php from scratch?

View Replies !
Linux Shell With PHP
Is there a way to log in to a Linux shell with PHP? possibly with exec(), passthru()....or something else?

View Replies !
Commands Shell From PHP?
How can I execute a command shell from PHP? For example a ls -l from PHP, What is the command?

View Replies !
Shell Scripting With Php
I Always hear the praise of Perl for Shell Scripting. But this is the first time I am hearing about Shell Scripting with PHP. I also tried this and worked fine. So, I am sharing with you. Please read this article for details:

View Replies !
Interactive PHP Shell - Can It Be Done?
I'm interested in implementing a command-line PHP app that takes input
line-by-line (for example, using Readline) and executes commands as
they are entered. It would need to know the difference between this:

echo "hello world";

which should be eval()ed after the first line, and this:

for ($i=0; $i < 10; $i==) {
echo $i;
}

which can't be executed until the block is closed.

I suppose I could try calling eval() and catching errors until it
works, but then how to distinguish between a data-entry error (e.g.,
"ecoh $i") and an error indicating that you're in the middle of a
possibly valid block?

View Replies !
Shell Commands
Is it possible to write a script that will run commands at a command prompt? say copying some files and changing ownership on some files, like an install script?

View Replies !
Shell Access Through PHP
I am in need of shell access like SecureSHell(ssh) or telnet via a PHP/PERL script to a remote server. Is there a way to do it without doing an exec("ssh hostname")?

View Replies !
Newline In The Shell
I have just written my first php script that runs as a shell script. I
run it using CLI that comes with my Win32 distro of php (4.3.4).
Everything’s works nicely accept for one thing: ‘
’ doesn’t work in my
echo statements. So in practices:

echo "hello
world"; becomes helloworld and not
hello
world

I have a suspicion that it has something to do with windows using a
different kind of new line syntax than Unix, but I can’t remember/find
an example of how it should be done.

In case this is the problem, what is the proper syntax, and if not what
is the problem then?

View Replies !
Run Php Directly At Shell
how to config the linux to know the path of /usr/bin/php so no need to type
it before running a php script every time?

View Replies !
PHP Shell Commands
Some php applications store database passwords into files which can be
read by the user www-data.

So, a malicious user which can write php scripts could read those passwords.
What should I do to prevent users from viewing those passwords?

View Replies !
Shell Script In Php
I have a new project that needs to add users to the linux system. They have to have a user name and password assigned. I know I can use the:

exec('adduser test -p password');

Now that should add a user test with the password password. But when I run my ftp program and try to use the user name and password it won't work. If I execute the same in linux command but with just:

adduser test
passwd test

it will work. Aren't these two commands the same?

View Replies !
Use Shell Script In The PHP?
I would like to take back of my database of postgress. now i am doing the command "pg_dumb " which written in a shell script and run it on command promt How it will do with PHP? Can i use that shell script in the PHP? Is there any need to establish database connection when using pg_dump. My shell script was like:

pg_dump -f /root/backupfolder/testfile.sql -h sourcedomain databasename

It didnt worked with shell_exec. why?
I tried with the code
<?
shell_exec('pg_dump -f /root/backupfolder/testfile.sql -h sourcedomain databasename');
?>

what is the problem? Is there any alternative solution to the problem??

View Replies !
Connect From Shell
Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by

server; consider upgrading MySQL client in /var/docs/lib.php on line 100
Could not connect: Client does not support authentication protocol requested by server; consider upgrading MySQL client

I can connect from shell, cant' from php.

View Replies !
SSH Shell Access
Looking for a reliable web host with fast cutomer support that supports ssh shell access? Can pay $10-15/month. Any recommendations? I have been using axishost.com and webclickhosting.com with great success, but want to try a third one.

View Replies !
RUN Run Shell Script
i have files called "spiralsconf.sh" and "spirals.cpp". my aim is to build a website using php programming language. i need to run "spiralsconf.sh" through php scripts. and i dont know how to do that. "spiralsconf.sh" is to get numerical values from the user and run spirals.cpp. so how do i run this shell script through php scripts?

View Replies !
Remote Shell
Is it possible to execute a shell script on a remote HP Unix server from a PHP page running on a Apache Server in Win XP ?

View Replies !
Shell Access Using PHP
I wasn't sure if there were a native-born process to determine if you have shell access using PHP, so I wrote my own, but not sure if I've covered everything, PHP Code:

if (!function_exists('is_shell_executable')) {
/**
  * Determine if the shell command is executable.  Uses {@link http://us3.php.net/manual/en/features.safe-mode.php#ini.safe-mode-exec-dir "safe_mode_exec_dir"} system-defined variable
  *
  * @access public
  * @param mixed $kommand Shell command
  * @return boolean
  * @see in_array_partial
  */
function &is_shell_executable($kommand) {
    if (!$kommand) trigger_error('Command not provided', E_USER_WARNING);
    // CHECK TO SEE IF $kommand IS WITHIN THE safe_mode_exec_dir
........................

View Replies !
Php Shell Scripts
I was wondering if the shell scripts if uploaded to your public directory can view directories beyond the public domain? I'm re-do'n the security on my site a bit and was just wondering because if it can't then I can move all my included type files outside the public domain.

View Replies !
Shell Scripting
is it possible to do shell scripts in php like i have a script that makes zip files and i want php to use it and if i want to server to restart i can use apachectl restart
and other things like that.

View Replies !
Run Shell Commands With PHP
I want to run few shell commands with PHP. I need to run lsof i :<port_no> and kill all the process running on that port number. I tried"

<?php
$output = shell_exec('lsof -i :8080');
print "<pre>".$output."</pre>";
?>

View Replies !
Executing A Shell Command
I try to use the backtick "`" to exacute a shell command from a PHP script. However, `touch file`; doesn't make the file. Neather does exec(), system(), etc. They all work when is used a different command, such as pwd, or ls. So what's a brotha gotta do to creat a file?

View Replies !
Displaying Shell Commands
How would I display a information on my website identical to how it would look if i typed it on a shell? For example, if I type df at the shell it puts each different partion on its own line. If i do: system("df"); It all gets jammed in to one line.

View Replies !
Running Shell Command Within Php
According to the manual for PHP, I should be able to run a shell command
within php.

I'm trying to copy some php files from one location to another one using
exec() but fail.

Code: ( text )

View Replies !
PHP / Cron / Shell Script
So I have a cronjob running every 5 minutes that calls a shell script. This shell script executes a php template that processes the creation and sending of customized mail.

This works great most of the time, except when it runs with 150k + entries. Then the script runs, finishes all it needs to do, and keeps running. This puts a huge load on the server and eventually goes haywire enough to take down the server.

I know that the script finishes its business, cause it's writing to a log along the way. The final entry gets written, but the process never gets killed. After the last occurence, I tried forcing an exit(); call, which did not fix the problem.

I am a little at a loss as to what the problem is. The script takes 4-6 hours to run completely. During this time, a file pointer is kept open for the log to write to. I've changed this today to have the script open and close the log file on demand, but I doubt this will fix the problem. This problem does not occur when processing smaller amounts (like 20k entries).

I'm pondering the idea of doing a system call for the script with a killall php or some way of identifying the process id of the cronjob script and killing that.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved