0

I need a solution that basically tails a log file from a remote box...

  1. Works on Mac
  2. Restores itself whenever I have internet. (I frequently close and open the lid of my macbook)

It could be a script that I keep running in terminal... I just need it to always reconnect as I switch networks etc.

Some things i've tried

I wrote a script which monitors the ssh command that tails and figured I could restart it whenever the process dies... The problem is the ssh doesn't seem to actually die in the sense the process actually exits... it gets into some state where it's no longer tailing from the remote file though.

while [ 1 ]; do
    # timestamp
    ts=`date +%T`

    f=log.txt
    TEST=`ps aux | grep "[s]sh -f ubuntu@production.myserver.com tail -f /var/log/myapp/$f"`
    if [ "$TEST" != "" ]; then
        echo "$ts it's running"
    else
         echo "$ts (Re)Starting $f"
         ssh -f ubuntu@production.myserver.com "tail -f /var/log/myapp/$f" >> ./logs/$f
    fi

  sleep 15
done

I thought this was the solution but didn't have any luck getting it compiled: http://www.harding.motd.ca/autossh/

blak3r
  • 731
  • 1
  • 11
  • 16
  • 1
    Why do you want to tail a remote log file ? Perhaps there are better ways of doing what you want to do. – Lawrence Mar 20 '14 at 05:38
  • @Lawrence Generally it's software development. I just hate having to restart tailing all the time. It's also generally just faster if I have the info on my box when I need it... don't want to download multi gig files at once... It also is a poor mans monitoring system... I use logMX as my viewer and can setup configurable alerts. It doesn't replace things like nagios but I find there are certain events I want to monitor and no about when they occur. – blak3r Mar 20 '14 at 10:22

0 Answers0