简体   繁体   English

如何通过Capistrano 2 Deployment ruby​​脚本在SSH服务器上执行php脚本

[英]How to execute a php script on ssh server through a capistrano 2 deploy ruby script

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. 我需要从capistrano 2部署脚本在部署服务器上执行php脚本,并且需要获取变量中的输出。 I am trying following command which is used to execute shell in ruby 我正在尝试遵循用于在ruby中执行shell的命令

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". 我收到“无法打开文件”错误,这是因为它试图从所需服务器上的本地服务器上运行此php。我能够在部署服务器上执行常规的“运行”命令,但具有不知道在变量“结果”中获取输出。

I am able to execute this php on serevr by following command but not able to capture the output in the script back. 我可以通过以下命令在serevr上执行此php,但无法在脚本中捕获输出。

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

Please help.. Thanks!! 请帮助..谢谢!

How about this: 这个怎么样:

result =%x[ssh username@remote.server 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 ) 有关设置SSH使其实现这一点的一些信息(我在https://unix.stackexchange.com/questions/112087/broadcast-or-send-machine-可读-code-to-ssh-clients / 112093#112093上发布了此信息)

Step #1 第1步

First make sure the client box (running that Ruby) has a SSH private key set up on it: ssh-keygen . 首先确保客户端盒(运行Ruby)上设置了SSH私钥: ssh-keygen

Step #2 第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. $ {user}是功能更强大的计算机上的用户名。

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------- ). 另外,请确保在功能强大的计算机上,/ /home/${user}/.ssh/具有权限700( drwx------ ),并且/home/${user}/.ssh/authorized_keys具有权限600 ( -rw------- )。 Use chmod to set permissions: 使用chmod设置权限:

$ chmod 700 /home/${user}/.ssh/
$ chmod 600 /home/${user}/.ssh/authorized_keys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM