Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tail a remote file?

I am trying to find a good way to tail a file on a remote host. This is on an internal network of Linux machines. The requirements are:

  1. Must be well behaved (no extra process laying around, or continuing output)

  2. Cannot require someone's pet Perl module.

  3. Can be invoked through Perl.

  4. If possible, doesn't require a custom built script or utility on the remote machine (regular linux utilities are fine)

The solutions I have tried are generally of this sort

ssh remotemachine -f <some command> 

"some command" has been:

tail -f logfile 

Basic tail doesn't work because the remote process continues to write output to the terminal after the local ssh process dies.

$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 $_; } 

This works better because there is no output to the screen after the local process exits but the remote process doesn't figure out that its socket is down and it lives on indefinitely.

like image 661
Frosty Avatar asked Feb 19 '09 16:02

Frosty


People also ask

How do I open a remote file?

enter sftp://host/ and press Enter (replace "host" with your target host) The file system of the remote host will be displayed in file manager now, and you can navigate to your target directory and double-click the file to open it.


1 Answers

Have you tried

ssh -t remotemachine <some command> 

-t option from the ssh man page:

 -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. 

instead of

 -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. 
like image 55
innaM Avatar answered Oct 02 '22 14:10

innaM