ssh2_exec with a variable

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

Post Reply
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

ssh2_exec with a variable

Post by nayeemmz »

Hi,

I am trying to run a command on a remote machine using ssh2_exec. I can successfully get the result back. However, there is a catch:

I want to send the command with a variable name that I read from the users input.

for e.g ., if I type

$directory = '/usr/local';

ssh2_exec($connection, 'ls -ld /usr/local'); it works,

ssh2_exec($connection, 'ls -ld $directory'); does not work.

How can I make the second command to work. Is there a way or did I hit a dead end?


If there is any alternative, please let me know.

I appreciate it.

Thanks

-Nayeem
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Hi, this is the general discussion forum
General Discussion
[...]
This forum is not for asking programming related questions.
Your thread should be in
PHP - Code
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!
Variable substitution doesn't take place in single quoted strings.
see http://www.php.net/manual/en/language.t ... ng.parsing
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to PHP-Code.
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

ssh2_exec

Post by nayeemmz »

Thanks for moving it to the relevant forum. I will be careful in future.
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

sssh2_exec

Post by nayeemmz »

volka,

Thankyou very much.

That solved my problem.

I appreciate your help.

-Nayeem
Post Reply