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 Complete Forum Thread with Replies
Related Forum Messages:
Permission Denied Executing Shell Command
I am getting following error when executing shell command from PHP, where PHP/Apache is running as "nobody". du: '/home/example/mail': Permission denied du: cannot access '/home/example/mail/example.com/demo/': Permission denied.
View Replies !
Executing A Remote Script (unix Shell)
I would like to add a button on a PHP page which allows to execute a script on a remote machine (without a web server on it...) using login and password to access it. I've tryed to use a "system" and "rsh", but with the rsh I can't access with password.
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 !
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 !
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 !
Formatting Output Of `ls -l` Shell Command
As in the topic, I use www to execute shell command, in this case 'ls -l' and i get output like: total 8 drwx------ 11 lecichy staff 4096 Oct 15 18:18 Maildir drwx---r-x 3 lecichy staff 4096 Oct 13 19:28 public_html etc. but what If i would want to print to www only some columns. e.g. only filename and size like; dir contains Maildir size: 4096 public_html size 4096 or any other combinations, the point is if anyone has any ideas how to split the output of this command to variables on which i can easily operate? And maybe its possible to achieve it in the other way. What I mean is selecting filenames and so on as a regular strings from a specific line of text?
View Replies !
PHP Parsing Shell Command Results
I am running a shell command via a php started ssh connection to a mail server. I need to grab the data the shell command displays and then load them into variables or an array ... Can anyone give me ideas on how to do this ... Note: I posted this on alt.php.sql ... so this is a cross post...
View Replies !
Capturing Output From GPG Command In Shell...
I have finally sorted out that it was permissions that were preventing me from running the gpg commands I was trying to run and I can now run them. The problem is that I am having real trouble capturing the output from the commands I am running. Just to be clear; $output = shell_exec("ls -l"); echo $output; does echo to the browser what one would expect ( a long string containing the results of the command). Unfortunately, when I run this command: $output = shell_exec("/usr/local/bin/gpg --homedir /usr/home/manager/.gnupg -b test.xml"); and then I echo $output I get nothing out of the variable - I'm stumped. The command does work - I have run it on the server from the command line and it does sign the document by creating a detached signature (as I want it to do). Am I missing something?
View Replies !
Shell_exec() Command - Linux's Shell
I've came up with an issue when trying to work on Linux's shell using PHP it seems to work when I issue the following commands, shell_exec("iptables -h");, shell_exec("ls"); and shell_exec("ifconfig"); however when I'm trying to do something like this, shell_exec("iptables -L") or shell_exec("iptables restart"); it doesnt seem to work.
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 Command Lines...
I'm trying to execute a command line through ffmpeg.exe in php. Can anyone tell me how this is done. Also where should I have such an application installed relative to the root of the site?
View Replies !
Problem With Executing A Command From Within My Script
I'm working on a web-based mail quarantine management system, and am running into some problems getting it to run the command to release a message. The main exertp of the script is below: <?php echo "Releasing /var/amavis/quarantine/" . $_POST['release'] . " to user " . $_POST['user'] . "<br><br>"; $command = "/usr/sbin/amavisd-release " . $_POST['release'] . " " . $_POST['secretid']; echo $command . "<br>"; passthru($command, $return_val); echo "<br>" . $return_val; ?> End script This command works fine from the command line, but won't run using this code. It comes back with a return code of 13 each time. I've also tried the exec and popen functions in place of passthru() with no luck. If it matters any, amavisd-release is an executable Perl script.
View Replies !
Including External Php File And Executing A Command
I have two different servers, and i need to call a php of server B from server A, so i did this: SERVER A: index.php has: include('http://server-b/file.php'); The content of file.php is: phpinfo(); ... but phpinfo() throws info about server B instead of its parent file SERVER A.
View Replies !
Exec Command Executing The Program In The Background
i am running xampp on my computer from apachefriends.org, it's a apache server this is the php script <html> <head> <?php exec ('notepad'); ?> </head> </html> but when i execute the php script on my computer , notepad doesnt not run i used a process viewer and discovered that notepad is running in the background and i cannot see it does anyone know how NOT to make it run in the background? i wan to see the notepad window on the apache server (my computer)
View Replies !
Problem Executing Command Line Scripts On Win2003 IIS6 PHP4 Box
we're running an Win2003server with IIS6 and PHP4 in fastCGI config. When i try to use system() command to execute ffmpeg.exe it works ok when i run the PHP script from the commandline on the server, but when i run it from the webbrowser i get a return value: 128 and nothing happens. I checked for all the security settings, and everything seems fine. Does anybody have a clue where i should be looking?
View Replies !
Tracert :: Passing Command To Command Prompt Via Exec
I want to execute a "tracert" command in the command prompt via php (using windows) I've managed to use passthru() to open the command prompt (but it doesn't allow me to use it) and when I close it, it outputs the command prompt output in the browser. I don't mind whether the result is passed back to the browser to stays in the command prompt window (but that would use exec() I would think). So how can I tell the command prompt that launches to execute the line tracert 192.190.201.273 So far my experimental code is: <?php passthru("c:windowssystem32cmd.exe"); ?> EDIT: my backslashes have been stripped from the path, but you know what I mean!
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 !
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 !
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 !
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 !
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 !
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 !
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 !
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 !
Shell Script Results
I want to get into a remote server, tail a file, and see if the last line is an error or not. I think that I've figured out how to shell over and tail the file. I have the specific server information and filename/location all stored in a database. I can't figure out how to get the result of the tail into a variable so that I can search it for an ERROR string.
View Replies !
How Can I Run Shell Script In Program?
I have tried to write a php program to execute the shell script, but dont know why it is not successful lei? file: test.php <? system("/home/www/htdocs/ok"); ?> file: ok (permission 755) #!/bin/bash echo abc >> abc.txt Why it is not successful lei(still cant see any file named as abc.txt after run test.php)? I have tried other commands like shell_exec(), also not work.
View Replies !
|