following a log file over http

跟風遠走 提交于 2019-12-21 12:18:52

问题


For security reasons (I'm a developer) I do not have command line access to our Production servers where log files are written. I can, however access those log files over HTTP. Is there a utility in the manner of "tail -f" that can "follow" a plain text file using only HTTP?


回答1:


You can do this if the HTTP server accepts requests to return parts of a resource. For example, if an HTTP request contains the header:

Range: bytes=-500

the response will contain the last 500 bytes of the resource. You can fetch that and then parse it into lines, etc. I don't know of any ready-made clients which will do this for you - I'd write a script to do the job.

You can use Hurl to experiment with headers (from publicly available resources).




回答2:


I wrote a bash script for the same purpose. You can find it here https://github.com/maksim07/url-tail




回答3:


You can use small java utility to read log file over Http using Apche HTTP Library.

HttpClient client = HttpClientBuilder.create().build();
    HttpGet request = new HttpGet(uri);
    HttpResponse response = client.execute(request);
    BufferedReader rd = new BufferedReader(new InputStreamReader(
            response.getEntity().getContent()));
    String s = "";
    while ((s = rd.readLine()) != null) {
       //Process the line
    }



回答4:


You can use PsExec to execute command on remote computer. The tail command for windows can be found at http://tailforwin32.sourceforge.net/

If it has to be HTTP, you can write a light weight web service to achieve that easily. e.g., read text within a specified file from line 0 to line 200.



来源:https://stackoverflow.com/questions/1645549/following-a-log-file-over-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!