如何在远程计算机上的 Ruby ssh exec 上强制执行持续时间或超时
使用ruby ssh 执行在远程计算机上连续运行的 shell 进程。如何强制 ssh 进程运行一段时间,然后终止该进程,并结束 ruby ssh 调用,继续执行后续代码?
目的:在特定时间内使用 ruby ssh 在远程计算机上调用测试。
示例:
Net::SSH.start( hostname.to_s, username.to_s, :password => pw.to_s ) do|ssh|
output = ssh.exec("command line call that runs continuously")
end
我唯一能想到做的事情: a) 使用 Terminator 来环绕 ruby exec 调用一段时间 b) 在命令行调用周围使用 perl 辅助函数,如下所示 这里
一定有比这更简单的东西吧?
Using ruby ssh to exec a shell process that runs continuously on a remote machine. How can I enforce a duration for the ssh process to run and then have this process killed, and ruby ssh call end, moving on to subsequent code?
Purpose: invoke tests on a remote machine using ruby ssh for a specific duration.
example:
Net::SSH.start( hostname.to_s, username.to_s, :password => pw.to_s ) do|ssh|
output = ssh.exec("command line call that runs continuously")
end
The only things I can think of doing:
a) using Terminator to wrap around the ruby exec call for a duration of time
b) use a perl helper function around the command line call as shown here
There must be something simpler than this right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用向进程发送信号的看门狗/终结器是最常见的解决方案。请注意,远程进程可能必须单独终止!
另一种方法是让两端每 X 秒监视一次本地“信号量文件”...如果该文件中包含正确的 PID,则优雅地死亡!
所以一旦你的看门狗定时器到期,
您可以通过 scp 或 rsync 将该文件同步到远程计算机,然后在本地复制一个。并且两个作业都可以查找它们并自行终止..
当然您也可以发送像 SIGUSER 这样的 UNIX 信号
using a Watchdog / Terminator which sends a signal to the processes is the most common solution. Note that the remote process may have to be killed seperately!
Another way of doing this is to have both ends watch for a local "semaphore file" every X seconds... if the file is there with the correct PID in it, die gracefully!
So once your Watchdog timer expires,
you can sync that file to the remote machine via scp or rsync, and copy one locally. and both jobs can look for them and terminate themselves..
of course you could also send a UNIX signal like SIGUSER