简体   繁体   English

ssh在perl中打开远程计算机上的文件

[英]ssh to open a file on a remote machine in perl

I am having problems with ssh'ing to a remote machine and open a text file on that machine using Perl. 我在ssh'到远程计算机并使用Perl在该计算机上打开文本文件时遇到问题。 I am currently tailing the file as seen below, 我目前正在跟踪文件,如下所示,

my $remote_filename = '/export/home/fsv/sample.txt';
my $remote_host = 'bs16-s1.xyz.com';

my $cmd = "ssh -l $sshUser $remote_host tail -f $remote_filename |";

open  $inFile, $cmd or die "Couldn't spawn [$cmd]: $!/$?";

The connection times out and I see that file is not even close to being opened. 连接超时,我看到该文件甚至没有接近被打开。 I tried using Net::SSH and Remote::FIle as well with no avail. 我尝试使用Net :: SSH和Remote :: FIle也无济于事。 It would be great if I could get some assistance on this. 如果能在这方面得到一些帮助,那将是很好。

Thanks for your time. 谢谢你的时间。

You are actually blocking later in the program than you claim. 实际上,您在程序中阻塞的时间比您声称的要晚。 Specifically, you block where you read from $inFile until the handle returns EOF, which is why ssh exits, which is when tail exits. 具体来说,您将阻塞从$inFile读取的位置,直到句柄返回EOF,这就是ssh退出的原因,这就是tail退出的原因。 Since tail -f never exits (unless terminated by a signal), you never exit either. 由于tail -f从不退出(除非被信号终止),因此您也不会退出。 That's why switching to cat worked. 这就是为什么改用cat的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM