0

I am having problems with ssh'ing to a remote machine and open a text file on that machine using 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. It would be great if I could get some assistance on this.

Thanks for your time.

4

1 回答 1

1

实际上,您在程序中的阻塞时间比您声称的要晚。具体来说,您阻塞从哪里读取,$inFile直到句柄返回 EOF,这就是ssh退出的原因,也就是tail退出的时间。因为tail -f永远不会退出(除非被信号终止),所以你也永远不会退出。这就是为什么切换到cat工作。

于 2012-07-31T17:40:53.193 回答