从 Web GUI 远程执行交互式 shell 脚本

发布于 2024-07-14 23:32:28 字数 405 浏览 4 评论 0原文

我的项目需要通过 Web GUI 远程执行交互式 shell 脚本。 这意味着打印到脚本标准输出的内容必须在 GUI 上可用,并且必须从 GUI 获取用户输入并将其写入脚本的标准输入。

我的问题是 (a) 这是一个好主意吗(暂时搁置它是一个要求这一事实)? (b) 以前有人解决过这种问题吗? 如果是,“最好”的方法是什么?

编辑 #1:要执行的脚本与 Web 服务器不在同一主机上。

编辑#2:

感谢您的回复! 我担心浏览器端解决方案不符合我的目的,因为用户可以启动一个或多个脚本,可以关闭浏览器,在一段时间后回来检查脚本的输出并提供输入。

我提出的设计涉及将脚本的输出存储到不同的文件中,当用户启动浏览器时,它开始从文件中读取并不断轮询(通过 Ajax)直到脚本完成执行。

There's a requirement in my project to execute interactive shell scripts remotely through a web GUI. This means that stuff printed to the standard output of the script has to be made available on the GUI, and the user input has to be taken from the GUI and written to the standard input of the script.

My questions are
(a) Is this is a good idea (setting aside for the moment the fact that it is a requirement)?
(b) Has anybody solved this kind of problem before? If yes, what's the 'best' way to go about it?

EDIT #1: The scripts to be executed are not located on the same host as the web server.

EDIT #2:

Thanks for your responses! I'm afraid that browser-side solutions won't fit my purpose because the user can start off one or more scripts, could close the browser, come back after sometime to check on the scripts' outputs and provide input.

The design I've come up with involves storing the output of the scripts to different files and when the user fires up the browser it starts to read from the files and keeps polling it (via Ajax) until the scripts have finished executing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

七色彩虹 2024-07-21 23:32:29

似乎您需要某种后台进程才能使其工作。 您无法通过单个脚本来完成此操作,因为当这样的脚本运行时,浏览器认为它正在加载页面。 如果这花费的时间比预期的要长,它就会中止并指出这一点。 “服务器响应时间太长”

所以实际上您需要生成/分叉一个单独的进程,并从客户端向服务器定期发出请求,这将导致服务器端脚本连接到该进程并与其交换消息。

例如,请参阅 phpterm

Seems like you need some sort of background process for this to work. You cannot do it from a single script, because while such a script is running - the browser thinks it is loading the page. If this takes longer than it anticipates, it aborts and states that. "Server took too long to respond"

So in fact you need to spawn/fork a separate process, and make periodical requests from client-side to the server, which will cause server side script to connect to the process and exchange messages with it.

See phpterm for example.

遇见了你 2024-07-21 23:32:29

听起来像计算机生成图像

Sounds like CGI

梦冥 2024-07-21 23:32:29

也许您有理由不考虑它,但是基于 Web 的 shell 进入服务器怎么样? 例如 AjaxTerm (http://antony.lesuisse.org/software/ajaxterm/)

作为我记得,您可以配置它可以登录的用户帐户,然后您可以应用常用的控件来限制用户可以运行哪些脚本(或 chroot?)。

毕竟,如果您想运行 shell 脚本,为什么不使用 shell 呢? :)

Perhaps you have reasons not to consider it, but what about a web-based shell into the server? e.g. AjaxTerm (http://antony.lesuisse.org/software/ajaxterm/)

As I recall, you can configure what user account it can login as, and then you can apply the usual controls to limit what scripts that user can run (or chroot?).

After all, if you want to run a shell script, why not use a shell? :)

柠檬 2024-07-21 23:32:29

这可能不是一个好主意。 交互式 shell 脚本通常不通过网页执行...

但当然这是可能的。

相反,想想您想要完成什么,并制作一个由标准 Web 组件组成的漂亮 UI。 也许你可以构建一些像“向导”一样工作的东西?

It is probably not a great idea. Interactive shell scripts are not usually executed through web pages...

but of course it is possible.

Instead think of what you want to accomplish and make a nice UI that is comprised of standard web components. Maybe you could build something that works like a "wizard"?

拥有 2024-07-21 23:32:29

您可以使用 Expect 来模仿用户将进程启动为 nohup 或后台作业,注销,然后定期重新登录以检查其日志文件或提供输入。

You could use Expect to mimic the user starting the process as a nohup or background job, logging out, then periodically logging back into check on its logfiles or provide input.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文