I need a solution that basically tails a log file from a remote box...
- Works on Mac
- 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 [email protected] tail -f /var/log/myapp/$f"`
if [ "$TEST" != "" ]; then
echo "$ts it's running"
else
echo "$ts (Re)Starting $f"
ssh -f [email protected] "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/
0 Answers