PHP CONNECTION WITH SHELL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
luyznascimento
Forum Newbie
Posts: 10
Joined: Wed Apr 04, 2007 9:46 am

PHP CONNECTION WITH SHELL

Post by luyznascimento »

Hi All !!!


I am facing a huge problem, at least to me, a newbie in Linux and a "newbie" with PHP related to this aspect specifically.

The main goal of my post is: TRY TO UNDERSTAND WHY I CAN T KEEP CONNECTED the necessary time to execute a communication with a developed shell programm.

If in the command line at linux - the code below when its called works PERFECTLY. It's divided in two parts: a) changes the actual directory to the "dynamic one"; b) TAR the content of that directory.

Code: Select all

#!/bin/sh
#

if test -z $1

then

        echo "empty directory - please inform one..."

else

        cd "$1/"

        tar -cf "$1.tar" cbq*

        #ls -al
fi
I tried different approaches with PHP like: shell_exec, system... but none of them seems to work. I am imagining that the problem comes by the fact I have two actions with this shell and php "get confused with it" when try to deal with it. The shell is called: cd.sh and chmod 755 .

I really need a help with this.

Thank you very much for your reading and forgive my "english".

Kind Regards,
Luyz Nascimento.
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

you can try:

Code: Select all

exec( "/path/to/program/your_program.sh" , $output);

print_r($output);
remember that php scripts from the browser are run as apache user (www-data or nobody) and you have to give permissions to that user.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Duplicated thread. Locked.

viewtopic.php?t=65977
Locked