0

I need to execute a php script on the deployment server from capistrano 2 deploy script and need to get the output in a variable. I am trying following command which is used to execute shell in ruby

result =%x[php -q #{myDeployPath}/myfile.php]

I am getting "Could not open file" error , this is because it is trying run this php on my local server from where I am deploying on the required server.I am able to execute normal "run" command on the deployment server but have no idea getting output in a variable "result".

I am able to execute this php on serevr by following command but not able to capture the output in the script back.

 run "php -q #{myDeployPath}/myfile.php"

Please help.. Thanks!!

1 Answer 1

1

How about this:

result =%x[ssh [email protected] php -q #{myDeployPath}/myfile.php]

Some information about setting up SSH to make this possible (I posted this at https://unix.stackexchange.com/questions/112087/broadcast-or-send-machine-readable-code-to-ssh-clients/112093#112093 )

Step #1

First make sure the client box (running that Ruby) has a SSH private key set up on it: ssh-keygen.

Step #2

Then make sure the public key for said private key is on the remote computer. You need to put it at the end of a file with a name like this:

 /home/${user}/.ssh/authorized_keys

${user} is the username on the more powerful computer.

Also, make sure on the powerful computer, /home/${user}/.ssh/ has the permissions 700 (drwx------), and /home/${user}/.ssh/authorized_keys has permissions 600 (-rw-------). Use chmod to set permissions:

$ chmod 700 /home/${user}/.ssh/
$ chmod 600 /home/${user}/.ssh/authorized_keys
Sign up to request clarification or add additional context in comments.

1 Comment

Capistrano script executes all other commands without requiring ssh again , do I need ssh again for executing a php and getting its result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.