加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 如何拖尾一个远程文件?

发布时间:2020-12-15 21:25:20 所属栏目:大数据 来源:网络整理
导读:我试图找到一个好的方法来拖动远程主机上的文件。这是在Linux机器的内部网络上。要求是: 必须良好的行为(没有额外的过程放置,或继续输出) 不能要求有人的宠物Perl模块。 可以通过Perl调用。 如果可能,不需要在远程机器上定制脚本或实用程序(常规linux实用
我试图找到一个好的方法来拖动远程主机上的文件。这是在Linux机器的内部网络上。要求是:

>必须良好的行为(没有额外的过程放置,或继续输出)
>不能要求有人的宠物Perl模块。
>可以通过Perl调用。
>如果可能,不需要在远程机器上定制脚本或实用程序(常规linux实用程序很好)

我试过的解决方案一般是这样的

ssh remotemachine -f <some command>

“一些命令”已经:

tail -f logfile

基本尾不工作,因为远程进程在本地ssh进程死后继续将输出写入终端。

$socket = IO:Socket::INET->new(...);
$pid = fork();
if(!$pid)
{
  exec("ssh $host -f '<script which connects to socket and writes>'");
  exit;
}

$client = $socket->accept;
while(<$client>)
{
  print $_;
}

这更好,因为在本地进程退出后没有输出到屏幕,但远程进程没有弄清楚它的套接字已关闭,并且它无限期地存在。

解决方法

你有没有尝试过
ssh -t remotemachine <some command>

-t选项从ssh手册页:

-t      Force pseudo-tty allocation. This can be used to execute 
         arbitrary screen-based programs on a remote machine,which
         can be very useful,e.g. when implementing menu services.
         Multiple -t options force tty allocation,even if ssh has no local tty.

代替

-f      Requests ssh to go to background just before command execution.  
         This is useful if ssh is going to ask for passwords or passphrases,but the user wants it in the background.
         This implies -n.  The recommended way to start X11 programs at a remote
         site is with something like ssh -f host xterm.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读