Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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)


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!!

share|improve this question

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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