How to connect PHP and Shell Scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to connect PHP and Shell Scripts
# 1  
Old 03-19-2007
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 06:47 AM.. Reason: remove email id
# 2  
Old 03-19-2007
Do not post your email address in any posts. You are violating rule #10 of the rules.
# 3  
Old 03-19-2007
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  
Old 03-19-2007
You will definitely need to be root on the server, as most shared hostings do not allow "exec" in php due to security concerns.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to connect

hello i try to made a report to conect all database to diferent OS HP-UX/LINUX/SOLARIS/AIX this is my example i have 5 db OS are HP-UX ps -fea | grep pmon root 1120 1 0 Nov 29 ? 5:14 ipmon -sD oracle 10286 1 0 Nov 29 ? 27:19 ora_pmon_BD1 oracle 10431... (7 Replies)
Discussion started by: ceciaide
7 Replies

2. Shell Programming and Scripting

Problem connect to a different server then do sudo login and finally run some scripts and get result

I have to write a shell script in my current linux server and I have to connect to a different server then do sudo login and finally run some scripts residing in a particular directory and get results back. I am starting to write my shell script as below but after I do ssh login it prompts for... (2 Replies)
Discussion started by: Devesh5683
2 Replies

3. UNIX for Advanced & Expert Users

Running multiple php scripts into one php only, cron mail alert problem...

hi, while separated they produce the usual mail alert and i can see the output... if i write into the php script: <?php system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script1.php'); system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script2.php'); system('php -f... (0 Replies)
Discussion started by: 7stars
0 Replies

4. Shell Programming and Scripting

Connect to DB2 table using Shell scripts

Can anyone please help me with an unix shell script to connect a DB2 database. My requirement is just to display the no of records present in a table of a DB2 database through Unix Shell script. Thx - Ram (1 Reply)
Discussion started by: onlyraja
1 Replies

5. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

6. Shell Programming and Scripting

Script to connect to a remote server and execute scripts

Hello All I need a script or set of commands which can establish a remote connection with another server and execute some scripts over there. Basically it has to establish the connection with the remote server as an user ,say 'testuser' and then execute the script 'testscript'. and return the... (5 Replies)
Discussion started by: sgbhat
5 Replies

7. Shell Programming and Scripting

How to connect unix server to unix server through shell scripts

Hi, I would like to connect UNIX server to UNIX server through shell scripts and i have some concepts . But i am totally confused how to connect UNIX server to UNIX server throuth running a script. It will be greatful to me if any buddy will help me. with simple example please. Thanks in... (2 Replies)
Discussion started by: phatan
2 Replies

8. Shell Programming and Scripting

How to connect unix server to unix server through shell scripts

Hi, I would like to connect UNIX server to UNIX server through shell scripts and i have some concepts . But i am totally confused how to connect UNIX server to UNIX server throuth running a script. It will be greatful to me if any buddy will help me. Thanks in advance. Phatan:) (2 Replies)
Discussion started by: phatan
2 Replies

9. Shell Programming and Scripting

connect to sqlplus from shell

I'm writting a shell script and at the begining I login to sqlplus by sqlplus -l user_name/password@instance what I would like is to check if the database is down or not , and if the database has started moved to the next step else sleep for a certain time and then check again . I know how to... (4 Replies)
Discussion started by: aya_r
4 Replies

10. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies
Login or Register to Ask a Question