Grant Grant - 1 year ago 70
PHP Question

Passing PHP variable to remote bash script

Is there a method similar to PHP's GET for bash scripts?

This is what I'm trying to do...

PHP file sets a variable and executes a remote bash script, the variable gets passed and is used in the bash script.

So this is my PHP script...

$myvar = 'hello world';

$connection = ssh2_connect('', 22);
ssh2_auth_password($connection, 'username', 'password');

$stream = ssh2_exec($connection, '/usr/incoming/');

And this is on the remote machine...

echo $myvar

Of course this isn't working because I'm not sure how to pass $myvar from the PHP file to

I know with PHP this is done using GET but how do I do this in this situation?


As @Phylogenesis commented, you want to simply put the variables after the script call, then call in the bash script use $1 to read the var:

$stream = "/usr/incoming/ " . escapeshellarg($myvar);

Your bash script would look like:

 echo "$1"