对于特定的bash命令,当我在完成后在本地执行它时,我获得了shell,但是当我远程执行时,shell会像这样挂起:
[user@host ~]$ ruby bin/remote_control.rb server start_server1
Running /home/server_manager.sh start_server ... wait
[]
当我使用ruby和NET :: SSH远程调用此命令时,必须按ctrl + C才能再次获得shell提示符并按Enter键不起作用。
远程脚本/命令/home/server_manager.sh再次没有此行为 本地调用
为了获得终端,脚本具有以下语法:
我正在尝试在背景中执行`commmand &` 2>&1 | echo "\n"
下面的ruby代码用于调用上面的脚本:
Net::SSH.start(@hostname, @username, :password => @password) do |ssh|
channel = ssh.open_channel do |ch|
ch.exec @cmd do |ch, success|
raise "Could not execute command: #{cmd}" unless success
ch.on_data do |c, data|
begin
if !data.nil? then
print data
else
exit
end
rescue SystemExit
puts "Rescued a SystemExit exception"
end
end
ch.on_extended_data do |c, type, data|
begin
if !data.nil? then
print data
else
exit
end
rescue SystemExit
puts "Rescued a SystemExit exception"
end
end
ch.on_eof do |ch|
puts "Cmd finished with success: #{@cmd}"
$LOG.info("Cmd finished with success: #{@cmd}")
end
ch.on_close { puts "Done!" }
end
end
channel.wait
ssh.loop
end
但直到现在我还没有成功。我需要添加到此代码中以始终释放shell。