2

I have a log file on remote server, and I need to tail -f it on local machine via ssh. The command is pretty trivial:

ssh -n [email protected] 'tail -f /path/to/remote/file'

Initially it works just great, but after some time (probably 1-3 hours) it stops working: there are new lines in the remote log file, but it isn't updated here, on local machine. No error is echoed, it just stops working. I have to interrupt it by pressing Ctrl+C and restart the same command, and it starts working again, for some time.

Internet connection is 100% working, because at the same time I have interactive SSH session to the same remote server, and it keeps working always.

What could be the problem, how to solve it?


Just in case, I'd say what I'm trying to achieve: it's just about remote irssi notifications. I have a server on which irssi is always running in tmux session, and I want to receive notifications on my desktop. So that important events (start_notification/stop_notification) are written to the log file, and my local script reads this log and manages notifications (tray icon, sound, libnotify's event)

And, as I already said, it stops working after some time, until I restart it.

My desktop OS is Linux Mint 13 MATE, server OS is Debian 3.2.51-1

Any help appreciated.

3 Answers 3

3

You should check the

/etc/ssh/sshd_config

file on your server, it should have the following options enabled:

TCPKeepAlive yes
ClientAliveInterval 60

or when opening the connection use the following options in your ssh command:

ssh -o TCPKeepAlive=no -o ServerAliveInterval=60

an other option is to just keep some action by running something like:

sh -c 'while echo "Still Active" ; do sleep 20 ; done'&

you could also put this in your login script so you do not need to enter this manually.

2
  • Thanks, I'll test it for some time to make sure, really hope it helps. But could you please elaborate on TCPKeepAlive=no? It sounds strangely, in case I want to keep connection alive :) Feb 22, 2014 at 18:53
  • TCPKeepAlive does not always work and the default is yes (I think), instead of this mechanism we switch to a different system which actively asks every 15 seconds for a server reply to keep the connection alive. Maybe there is no need to disable the TCPKeepAlive but usually they do and there is no need for when you use ServerAliveInterval.
    – Requist
    Feb 22, 2014 at 19:00
1

ssh -o TCPKeepAlive=yes -o ClientAliveInterval=60

ClientAliveInterval is for the server side ie. it will only work with sshd.

Instead, use:

ssh -o TCPKeepAlive=yes -o ServerAliveInterval=60

Also consider:

ServerAliveCountMax

Here's a good reference: https://unix.stackexchange.com/questions/34004/how-does-tcp-keepalive-work-in-ssh

0

Here is a simple solution with a collateral advantage (I'll let you guess):

ssh -n [email protected] 'while : ; do
        date "+--  %H:%M:%S  --"
        sleep 20
        done &    
    tail -f /path/to/remote/file'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .