I use Net::SSHv2 to connect to a server and start a script on that server. So far it is working, but I want to interrupt the script when it is running for over 10 minutes or the output file gets too big. After receiving the interrupt the script will shutdown and output some statistics.
My current code looks like this:
File.open(filename, "w") do |f|
Net::SSH.start(host, user, password: password) do |ssh|
ssh.exec! "do_work" do |channel, stream, data|
f << "data"
#break if f.size > 1024 * 1024 * 100 #file size > 100 MB
#channel.send_data "^C" if f.size > 1024 * 1024 * 100 #file size > 100 MB
end
end
end
I tried a couple of other things with opening a block for the channel and requesting a shell, but it didn't work.