简体   繁体   English

将http文件的内容打印到shell?

[英]printing contents of a http file to a shell?

I want to be able to retrieve the contents of a log file stored on a server in the form of: 我希望能够以下列形式检索存储在服务器上的日志文件的内容:

http://[SOME SORT OF ADDRESS]/file.txt

and print it to a shell which can refresh using something like 'watch' to keep a real time track of this log from a shell rather than having to use a broweser. 并将其打印到一个shell,它可以使用像'watch'这样的东西进行刷新,以便从shell中实时记录这个日志,而不必使用浏览器。 Is there any neat and simple way of doing this (possibly later wrapped up into a python script). 有没有任何简洁明了的方法(可能后来被包装成python脚本)。

这将每0.1秒获取一次请求的URL并显示在控制台上

watch -n 0.1  wget -qO- http://google.com

Yes tail -f works on Linux. 是的tail -f适用于Linux。 However this will only work on local files. 但是,这只适用于本地文件。 If the file is remote you will have to repeatedly fetch it to keep the updated (I think). 如果文件是远程的,你将不得不重复获取它以保持更新(我认为)。

也许你可以尝试这样的事情:

watch "wget -N http://[SOME SORT OF ADDRESS]/file.txt &> /dev/null; cat file.txt"

while sleep 60; do
    curl address
done

Will print out once a min 将每分钟打印一次

Adjust to your liking 根据自己的喜好调整

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM