Tail an http resource

httptail

Is there a way to tail a resource such as http://someserver.com/logs/server.log ?

This is what I would do for a local file.

tail -F /var/logs/somefile.log

I would like something similar to that for a file accessed through the http protocol

Best Answer

This will do it:

#!/bin/bash

file=$(mktemp)
trap 'rm $file' EXIT

(while true; do
    # shellcheck disable=SC2094
    curl --fail -r "$(stat -c %s "$file")"- "$1" >> "$file"
done) &
pid=$!
trap 'kill $pid; rm $file' EXIT

tail -f "$file"

It's not very friendly on teh web-server. You could replace the true with sleep 1 to be less resource intensive.

Like tail -f, you need to ^C when you are done watching the output, even when the output is done.