The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how will i connect postgres database from unix shell script jambesh Shell Programming and Scripting 3 07-16-2008 12:09 PM
connect to sqlplus from shell aya_r Shell Programming and Scripting 4 02-07-2007 05:52 AM
How to connect to database db2 through Unix Shell Script ankitgupta Shell Programming and Scripting 3 10-31-2006 09:50 AM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-12-2006 03:27 AM
Connect to sybase database using Korn shell script bhgopi Shell Programming and Scripting 7 08-10-2005 10:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2007
krishna_sicsr krishna_sicsr is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 25
How to connect PHP and Shell Scripts

Dear Friends,
Plz some one tell me how to connect PHP and Shell Scripts.

Mail me on address removed by moderator

Thanks
Nishant

Last edited by blowtorch; 03-19-2007 at 05:47 AM.. Reason: remove email id
  #2 (permalink)  
Old 03-19-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Do not post your email address in any posts. You are violating rule #10 of the rules.
  #3 (permalink)  
Old 03-19-2007
strobotta strobotta is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 10
what do you mean by connecting PHP with shell scripts?

in PHP you can use shell scripts/single commands by using
exec
passthru
system

see http://php.net for more details on these commands.

PHP Code:
exec("uname -a"$res$err); 
$res holds the outbut of the shell command. $err contains the error code (normaly 0 if everything works ok).

Having a shell script you can use PHP like this:

Code:
#!/bin/sh

MY_LOCAL_DATE=`php -r 'echo "today is ".date("l d.m.Y", time());'`
echo $MY_LOCAL_DATE

In this case you have to echo the output of your PHP stuff, to receive the
result and save it to a variable.

The following code demonstrates how to access shell variables within PHP

Code:
#!/bin/sh

export MY_PWD=`pwd`
MY_OUTPUT=`php -r 'echo "we are in directory ".$_ENV["MY_PWD"];'`
echo $MY_OUTPUT

  #4 (permalink)  
Old 03-19-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
You will definitely need to be root on the server, as most shared hostings do not allow "exec" in php due to security concerns.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0