dtiopy6088 2013-03-19 17:39
浏览 76
已采纳

有什么方法可以从网页执行bash脚本并在执行时捕获输出?

I got some long running bash scripts on my Ubuntu 10.04 Server that are doing things like backups and database dumps.

I'm currently executing them via cron and mailing me the results. However it would be nice to trigger them manually throughout a Webinterface additionally. (I do not want to give any user SSH access so he can trigger the scripts)

In PHP, for instance, there is the exec Command which obtains the Script output AFTER the Script has finished. This is not useful since the Scripts last longer than the 30 Seconds Browser Timeout. (And I want to monitor the progress) So I'm currently stuck in finding a way on how to gather the Script output periodically or "tailing" and display it through JavaScript or Pagereloads or something like that.

As I noticed, Webmin for instance is somehow doing this when you run system commands like apt through their webinterface.

One way I could imagine is forking the script execution and redirecting the output to a file, whilst the Main Process is reading it on Page reload/ Ajax request. But this sounds somehow like a workaround :)

So, does anyone have a good solution for this problem? Doesn't need to be PHP, could also be python or perl or anything else on server side. Or is there a tool or library for such things?

Any ideas greatly appreciated!

  • 写回答

3条回答 默认 最新

  • dongli7236 2013-03-19 17:44
    关注

    I am not sure if you mean to require PHP in your solution, but if not…

    In the past, I have used Jenkins for this kind of thing. You can use it as both a cron replacement and as a way to manually trigger scripts, all while keeping logs of what happens.

    Jenkins can be set up such that some users only have permission to trigger jobs, as opposed to the Jenkins administrator who can do stuff like set up and edit jobs, etc.

    And if you like getting email, Jenkins can do that too. If anything, the biggest downside to Jenkins is that it is super-flexible / configurable, and so not always obvious how best to set it up for one's particular needs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误