Is it possible to tail -f an external web resource?

1

Can I tail -f an output from http://example.com?

I want to monitor external JSON file.

Szymon Toda

Posted 2014-01-18T11:37:53.713

Reputation: 1 239

1How do you access this JSON file? Is it on a network share? On a pc to which you have ssh access? On the same machine under a different account?... – MariusMatutiae – 2014-01-18T13:24:00.730

Answers

2

No. From the tail(1) man page:

   With  --follow  (-f),  tail  defaults to following the file descriptor,
   which means that even if a tail’ed file is renamed, tail will  continue
   to  track  its  end.   This  default behavior is not desirable when you
   really want to track the actual name of the file, not the file descrip-
   tor (e.g., log rotation).  Use --follow=name in that case.  That causes
   tail to track the named file  in  a  way  that  accommodates  renaming,
   removal and creation.

This means that the tail command would need to the file descriptor to follow it, which it doesn't when you issue an http request. Your file system has no idea that a remote (in the sense that you are referring to) file has changed. To get something like this to work you would need to use a utility/script that polls the server at a specific interval or uses something like websockets (if the server supports that).

Samuel Lindblom

Posted 2014-01-18T11:37:53.713

Reputation: 208

0

One way of doing this would be to run wget on the target url in a loop and tail that:

$ while :; do 
   wget -qO - http://example.com >> /tmp/foo; sleep 1; 
  done

Then from another terminal run

$ tail -f /tmp/foo

terdon

Posted 2014-01-18T11:37:53.713

Reputation: 45 216

0

To use tail -f on an internet file you need that file to be locally readable and pollable. One way to accomplish that would be with HTTPFS, however this is not a commonly used or mature piece of software.

Sparr

Posted 2014-01-18T11:37:53.713

Reputation: 911