2

When a web page is loaded on server A i want it to run a script on server B. I can do this with a series of commands from server A by logging into server B and executing the script, but it needs to be done all in one statement so that PHP can execute it.

This works:

user@A$ sudo -u www-data bash
bash: /home/user/.bashrc: Permission denied

Then:

www-data@A$ ssh -i /etc/ssh/www-data/id_rsa remote@B
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-32-generic x86_64)

Then:

remote@B$ /home/web/script.php

(no output, but i can see the results in the database)

So i can see everyone has access to get the message where it's going. But when i try to combine it into one statement:

user@A$ sudo -u www-data bash
bash: /home/zen/.bashrc: Permission denied

(as apache / php would be)

www-data@A$ ssh -i /etc/ssh/www-data/id_rsa remote@B `/home/remote/script.php`

then I get:

bash: /home/remote/script.php: No such file or directory
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-32-generic x86_64) ....

It also keeps me logged in to B which is irrelevant but strange.

Then just as a sanity test, i continue from there to run the script:

remote@B$ /home/remote/script.php

Thanks in advance for any advice!!

2

The order of precedence with the quoting is likely the problem:

ssh remote@B `/home/remote/script.php`

is very different from:

ssh remote@B '/home/remote/script.php'

In the first, the shell is calling script.php - on the local machine - which likely returns nothing, so the command ends up being ssh remote@B, giving you an interactive shell.

The second command passes a statement (/home/remote/script.php) through ssh to the shell on the remote machine.

Trying changing your back-quotes to single quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.