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 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 !
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 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 !
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 !
Mail() Function Problem - Works In Shell Scripts, But Not In Http
I have a redhat 9 linux machine running apache 2.0.47, mysql 4.0.15, and php 4.3.4. I have been puzzled by this mail() problem for quite a while, could someone please give me some hint on this? I configured sendmail with a relay so that all outgoing mails go through our organization's exchange mail server: DSexchange.domain.com. The php.ini file specified the path to sendmail: "sendmail_path= /usr/sbin/sendmail -t -i". I can send email out from shell by doing ">mail lsun91125@yahoo.com". I also tested a shell script using php mail() function: ---------------------------------------------------- #!/usr/local/php/bin/php -q <?php $sent=mail("lsun91125@yahoo.com", "php email", "test this"); print "Send=$sent "; ?> ---------------------------------------------------- This works fine too. But when I tested the following script on the web, the email cannot be sent out. The browser returned with "Send=". There is nothing in the mail queue either. ---------------------------------------------------- <?php $sent=mail("lsun91125@yahoo.com", "php email", "test this"); print "Send=$sent "; ?> ----------------------------------------------------
View Replies !
Exec Function
Iv tried using this exec function and iv never used it before today.. im not completely sure what it does. <?php $command = "/movie/Without a Paddle.avi"; echo exec($command); ?> I hoped that this script would open up a movie, but it doesnt. I am using this function completely wrong or is there a problem with my code?
View Replies !
Exec() Function
I'm having trouble getting the exec() function to work in my script. I have never worked with this function and before I contact my server admin I want to verify my code is correct. script_name.php is in the same directory as this script that is running exec(). Is this correct? exec("./script_name.php &");
View Replies !
Function Exec
I'm trying to execute a command with "exec" but it doesn't work. Here is my code : PHP Code: exec("../../blast/blastall -p blastn -d est.txt -i testseq.txt -o test.txt"); I'm sure that my scrypt reads this line but nothing happen. Does someone know how to use this function ?
View Replies !
PHP Exec Function No Output
I am running PHP 5.1.6 (cli) on Linux. When i use the exec($cmd, $output, $return) command the $output array is always blank if the command had an error in it. There are only values if the command was successful. How do I capture the error text returned?...
View Replies !
Php Exec() Function Is Not Working
I am trying to execute linux command with php. I am try to log on as super user, so I have used the following code: exec("su root"); exec("<password>"); But I dont think its working, becuase if I want to change my directory and view the list, I find myself in the same directory. I have used the following code: exec("cd /"); Passthru("ls -l");
View Replies !
Ssh2 Mod And Exec Function
Something very strangne happens with the function ssh2_exec, i can't read the stream answer after execution in the remote computer. I work with apache 1.3.30 and php 4.3.10 , libssh 2.0.5 . the ssh2 module looks to work correctly but sftp functions cause a big delay causing server timeout and ssh2_exec can't read the output. Tryed many things recommeded in php website and forums but always the first ssh2_exec reading success and the following ones fail. $stream=ssh2_exec($conn_id,'/usr/bin/ls ./public_html'); I tryed to read the output with: stream_set_blocking( $stream, true ); $cmd=fread( $stream, 4096 ); after while($line = fgets($stream)) { $cmd .= $line; } and while( !feof($stream) ) { $cmd .= fgets($stream) } Nothing success to catch the output for the second execute order. In the same process only the first exec could be read. Anybody know
View Replies !
Can Not Execute Exec Function In Php
I am facing a strange problem , in linux server system commands like exec, system are enabled but one particular command is not working properly , either its returning null or 127. Command is exec(whois -h whois.crsnic.net "bnbnmnmbnmn.com") But this command is working properly in another linux server. Any suggestion is well come excepting reinstall or re-configuration as its not possible . Commands like exec('whoami') are working . Server:linhost161.prod.mesa1.secureserver.net 2.4.21-27.ELsmp #1 SMP Wed Dec 1 21:59:02 EST 2004 i686
View Replies !
Using Exec() Function In PHP5
I have problem by using exec() function in PHP5, Apache and Windows XP to run an external program from my PHP page reside on server. When I call my program using exec() the page just stops (waiting for www.mysite.com...). I have used by absolute path and result was same. Also, I have tested my PHP page by running by using PHP (or PHP-cgi) interpreter in command line and it just works fine without any problem. I don't know why it doesn't work when I call it from my page. Can anybody help ? I think it is something wrong with Apache or PHP settings. Am I right ?
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 Exec Function To Get A .exe Return Status Gives CGI Error
I'm trying to make a web page to work. It worked before so it has to be something related with the configuration. My problem is a call to a compiled executable (made for me) that returns 1 or 0. It does not print any text to the standard ouput so the error is strange: CGI Error: The script can .. because of the HTTP headers (I have it in spanish so the message is not the exact one). As supposed, the HTTP headers are needed only if the executable prints out a text to the browser but it's not the case. And (I repeat) It worked as it before. The machine had to be formatted and the guy in charge of that is not with me anymore.
View Replies !
Exec() Function Warning: Unable To Fork (Access Violation At 77F81B4D)
I am trying to execute a DOS command with the exec() function. All I get is fork errors or access errors, regardless of what file I try to execute. Example: <?php exec("sync.bat"); `sync.bat`;?> Warning: Unable to fork [sync.bat] in C:testexec.php on line 3 Warning: Unable to execute 'sync.bat' in C:testexec.php on line 4 PHP has encountered an Access Violation at 77F81B4D Id doesn't seem to matter what kind of file I try to execute, .exe, .bat or .com. Any ideas? Has ANYONE executed an external program under php/Windows?
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 !
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 !
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 !
Php Shell Script Trouble
I'm trying to write a simple php shell script that will read a text file (containing a list of files in a directory) into an array, then write the contents of each of the files listed in the text file into a new file in a different directory. Here's my script: Code:
View Replies !
How Can I Run Php Scripts From A Shell Script?
I want to run some php scripts from a shell script(bash?) the php script i want to run is this: test.php and it's path is this: home/virtual/blahblah.com/home/abc/mainwebsite_html/bluhbluh/dbtest/ 1. How would I creat the shell script? 2. How would I execute it? I have already tried ot figure it out with no success. I have php 4.2.2
View Replies !
Php Shell Script Issue
I'm executing a php shell script from within a php webpage using exec().. I am sending this php shell script some arguments that I access using the array $argv ($argv[0],$argv[1],etc). The shell script has: #!/usr/bin/php -q at the top. Now as far as I know, the -q is to suppress HTTP headers, but it returns this output (when the php webpage executes it): X-Powered-By: PHP/4.2.1 Content-type: text/html No input file specified. Note that the headers are still there. When I remove the -q it returns this: X-Powered-By: PHP/4.2.1 Content-type: text/html Warning: Division by zero in /path/to/shell/script/file on line 63 This is because NOW it's not getting the $argv vars (Still executed by the php webpage)...BUT... when I make the php webpage echo the command and all it's arguments (that I pass to the exec() function), copy it out and paste/execute it in the shell, the php shell script executes fine, with the -q (surpressing headers) or without the -q (showing headers)... no errors.. picking up ALL the arguments sent?? The webpage executes the shell script, but its like the arguments don't get sent without the -q, and with it, it just says: "No input file specified"... and executed from within a shell, all works fine??
View Replies !
Back Up Mysql Db From Shell
I need to update a remote database from a local one. I use mysqldump in my php page in order to create a file for each table, like this: $command="mysqldump table_products > table_products.sql"; system($command); This works perfect and it gives me a file with a drop-table, create-table and all the insert values. Then I need to connect to the remote server and run the table_products.sql file. The way I do that is by calling the following in my php page: $command="mysql --host=$host --user=$user --password=$pass --database=$db;"; system($command); , where $host, $user etc are being set at the top of the page. This works fine and I get connected to the remote database. Now I need to run the following mysql command: source stb_products.sql When I try this sequence from a command line (windows dos prompt), it works perfect. When I call "mysql --host=$host --user=$user --password=$pass --database=$db;" in command line I get the "mysql>" prompt, and the run the "source table_products.sql" and the remote database gets updated. When I do this through PHP the last command doesn't work. I guess I am not calling 'source' from within a "mysql" prompt? How should I do it? Any other ideas for achieving the same result? I need to do everything from a single PHP page that runs on a local machine. The full code is the following : //DUMP DATA IN FILE $command="mysqldump backcatalogue table_products > table_products.sql"; system($command); //CONNECT TO REMOTE DATABASE $command="mysql --host=$ohost --user=$ouser --password=$opass --database=$odb;"; system($command); //UPDATE REMOTE DATABASE FROM FILE $command ="mysql source table_products.sql;"; system("command ") ;
View Replies !
Running Shell Scripts
I have problems running a couple of shell scripts from PHP. I found a similar posting, so I posted my question to the original author. But unfortunately the original author is not at the address anymore. Anyone can help with the problems highlghted below? ---------- Forwarded message ---------- From: "paulhjwu@gmail.com" <paulhjwu@gmail.com> To: gmuldoon <gmuldoon_nospam@scu.edu.au> Date: Wed, 01 Feb 2006 16:55:49 +0000 Subject: Re: Problem calling a shell script gmuldoon wrote:[color=blue] > Help please. > > Setup: RH EL3, PHP 4.3.5, Apache 1.3.29 running as user "nobody". > > Have a bash script named shell_script. > > Telnet to server as user "nobody" ("nobody" having been given /bin/bash > as temp shell), can run this script from command line, no problems. > > Created a php script including the line: > system ("/path/to/shell_script"); > but get error message in apache error logs: > /bin/bash: /root/.bashrc: Permission denied > > Appears that PHP is using root environment rather than "nobody" env? > phpinfo seems to list env vars for root under the "Environment" section. > > Will compiling PHP as "nobody" instead of root solve or cause other > probs?[/color] Hi, I have a similar problem now. I am wondering whether you have found solution to the above. My script looks like the following: $cmd = "export JAVA_HOME=/usr/java/jdk1.5.0 " . "cd /opt/softwares/archive_system/nutchwax " . "ls -l " . "/bin/sh bin/indexarcs.sh -d /opt/softwares/archive_system/archive_data/nutch -s /opt/softwares/archive_system/archive_data/heritrix -n " . "cd /opt/softwares/archive_system/archive_data/nutch " .. "ls -l " . "/bin/sh /usr/tomcat/jakarta-tomcat-5.5.8/bin/catalina.sh stop " . "/bin/sh /usr/tomcat/jakarta-tomcat-5.5.8/bin/catalina.sh start " ;
View Replies !
How Can I Run Shell Command Without Getting Return?
I want to call any shell command from php script using shell_exec(). The problem is that the next line of the php script would not be run until a few minutes after running the shell command. I found the shell command couldn't be run at background mode. It seemed that the shell_exec() function waits a return from the command. Because the command doesn't return, the shell_exec() waits until timeout reached. Using the '&' at the end of the command doesn't work expected. So I want to know how can I run any non-background mode shell command from php script without waiting return. I'll look forward to any answer.
View Replies !
Execute Shell Interactive
I ve been trying to make a CLI script in PHP to execute /bin/sh and create a pipe for stdin / stdout / stderr. It should work like this. You start the script, it executes /bin/sh and passes the streams to the process it opened. Moreover I would like it to listen for connections with sockets. I have the whole script half-done, here's the code and explanation: Code:
View Replies !
|