我正在尝试检查另一台服务器上是否存在文件。
我正在使用Net :: SSH,因为需要密码并使用File.exist?
检查文件是否存在。当我运行代码时,它返回false,将host
更改为第二个服务器。
我猜测Ruby代码在do
会话中不起作用,或者我做错了吗?
require 'rubygems'
require 'net/scp'
exist = true
host = "msxafs02.usi.net"
port = 22
user = "root"
password = "password"
remote_path_prefix = "/home/appit"
remote_command = "/home/appit/bin/mast/appit_version_control.pl"
Net::SSH.start(host, user, :password=>password, :port=>port) do |session|
print host + " SSH started \n"
if File.exist?("/home/appit/bin/mast/appit_version_control.pl")
host = "msxafs02.usi.net"
print "file exist on msxafs02 \n"
else
host = "mdsxocd5.usi.net"
print "file doesn not exist on msxafs02 using mdsxocd5 \n"
end
end
print host + "\n"