Reputation: 186
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!!
Upvotes: 0
Views: 448
Reputation: 551
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 )
First make sure the client box (running that Ruby) has a SSH private key set up on it: ssh-keygen
.
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
Upvotes: 1