将我的命令行守护程序网络化的简单方法是什么?
假设我有一个在网络服务器上运行的简单守护程序类型脚本。 我在带有 gnu screen 的终端中运行它,这样我就可以密切关注它。 这很好用(顺便说一句,我使用这个技巧)。
但现在假设我想制作一个网页,可以在其中监视脚本的输出。 最简单的方法是什么?
注意:
- 这主要是针对我自己和几个合作黑客的,所以如果 websockets 是答案并且它只适用于 Chrome 或其他东西,这是可以接受的。
- 这个问题提出了类似的问题: How to make allconnected browsers reload launch by a server-side事件。但我希望有一个更简单、快速和肮脏的解决方案,尤其是一种通用方法,可以为我可能想通过浏览器关注的任何脚本快速执行此操作。
Suppose I have a simple daemon type script that I run on my webserver.
I run it in a terminal, with gnu screen, so I can keep an eye on it.
That works fine (incidentally, I use this trick).
But now suppose I'd like to make a web page where I can keep an eye on my script's output.
What's the easiest way to do that?
Notes:
- This is mainly for myself and a couple co-hackers so if websockets is the answer and it only works on Chrome or something, that's acceptable.
- This question is asking something similar: How to make all connected browsers reload initiated by a server-side event. But I'm hoping for a simpler, quick-and-dirty solution, and especially a general way to quickly do this for any script I might want to keep an eye on from a browswer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让您的守护进程将日志输出保存到可通过 Web 脚本访问的位置(例如数据库表),然后显示它。让网页每隔几秒更新一次。 (如果需要,您可以使用
XmlHttpRequest
和 Javascript 来完成此操作)编辑:
进行页面更新的最简单方法是使用
meta http-equiv="refresh" content="5">
标记。更优雅的是使用 Javascript - 您可以使用 PeriodicalUpdater for jQuery 之类的东西。这些解决方案都是轮询技术。有一个技巧可以使事件立即传播,称为彗星。但这有点复杂,坦率地说,民意调查可能很适合您的用例。
Let your daemon log output into a place that is accessible from a web script (Such as a database table), which can then display it. Have the webpage update once every few seconds. (You can get fancy at do it with
XmlHttpRequest
and Javascript, if you want)Edit:
Simplest way to have a page update, is with a
meta http-equiv="refresh" content="5">
tag. A bit more elegant is to use Javascript - You can use something like PeriodicalUpdater for jQuery.These solutions are both polling techniques. There is a trick you can pull to make the event propagate instantly, called comet. But that's a bit more complicated, and frankly a poll probably suits your use case fine.
这看起来确实很有前途(感谢我的朋友和非凡的黑客,David Yang):
http:// /blog.new-bamboo.co.uk/2009/12/7/real-time-online-activity-monitor-example-with-node-js-and-websocket
This looks really promising (thanks to my friend and hacker extraordinaire, David Yang):
http://blog.new-bamboo.co.uk/2009/12/7/real-time-online-activity-monitor-example-with-node-js-and-websocket