Page 1 of 1

ssh2_exec with a variable

Posted: Fri Jun 29, 2007 7:27 pm
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

Posted: Fri Jun 29, 2007 8:23 pm
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

Posted: Fri Jun 29, 2007 8:28 pm
by John Cartwright
Moved to PHP-Code.

ssh2_exec

Posted: Fri Jun 29, 2007 8:32 pm
by nayeemmz
Thanks for moving it to the relevant forum. I will be careful in future.

sssh2_exec

Posted: Fri Jun 29, 2007 9:41 pm
by nayeemmz
volka,

Thankyou very much.

That solved my problem.

I appreciate your help.

-Nayeem