I am trying to run a PHP script inside the ruby shell. While it is working perfectly if I am using the snippet directly in the ssh terminal, it is returning an error if executed with ruby:
zsh:1: command not found: php
Using this script below with commands like ls is working fine.
require 'rubygems'
require 'net/ssh'
host = "abc.de"
user = "user_xy"
pass = "user_pass"
begin
Net::SSH.start(host, user, :password => pass) do |ssh|
$a = ssh.exec! "cd xy_dir && php abc.phar do_this"
ssh.close
puts $a
end
rescue
puts "Unable to connect to #{host}."
end
How can I run PHP using Net::SSH?
Thanks for your help
`ssh host password command`? This might help narrow down the problem. 2) I recommend removing thessh.closecommand; the ssh session will be closed automatically when the block terminates. (File.open with a block works this way too.) 3) You may need to useShellwords.escapeon any strings you pass to a shell. 4) You should not need therequire 'rubygems'. 5) Are you absolutely sure that both cases (the success and the failure) are running on the same host?$PATHwhen you ssh to the machine?phpon the command line, what executable is that actually running? Try:which php, too see. Now, run:echo $PATH, you should also see that folder in which thephpexecutable lives. Now, try doing to above via the ruby script. What's the difference?