Richard Fernandez wrote: > There's a FAQ that deals with coding a "tail -f" if you're logfile is > on the same box as the perl script. > But what if you want to use rsh to tail a file remotely? > > Here's what I have: > ------------------------------8<------------------------------ > ---------8<--- > -------------------------------- > > #!/usr/bin/perl -w > use strict; > use Net::Rsh; > > my $host = shift or die "usage: my_rsh <hostname> <command>"; > my $cmd = shift or die "usage: my_rsh <hostname> <command>"; > > my $session = Net::Rsh -> new(); > > my @output = $session->rsh($host, '<local_user>', > '<remote_user>', $cmd) or > die; > > for (@output) {print;} > > ----------------8<----------------------------8<-------------- > -------------- > -----------8<---------------- > > and here's my command line: > > $ sudo my_rsh.pl <hostname> "tail -f /u01/app/apache/logs/access_log" > > It seems that I never reach the print statement... > > I've tried things like: > > open(OUTPUT, $session->rsh($host, '<local_user>', > '<remote_user>', $cmd) ) > or die; > while (<OUTPUT>) {print;} > > but that doesn't work.
The call to Net::Rsh::rsh is going to wait for the remote command to exit, and then return the output as an array of lines. But tail -f is never going to exit, so you need a different approach. Try a pipe open like this: open RSH, "rsh hostname tail -f /u01/app/apache/logs/access_log |" or die $!; print while <RSH>; close RSH or die $!; The print loop will run forever, so you'll have to interrupt your script. The remote process will end when it tries to write the next line (it'll get a SIGPIPE), or when the TCP keepalive detects that the client is gone. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]