通过SSH登录时,如何从新贵作业中获取输出?


10

为了监视我的作业定义在做什么,我想查看作业的文本输出。当我通过SSH登录时,这似乎是不可能的。

我在Natty 11.04中遇到此问题,但我坚信这是更常见的问题。

我使用的一个简单的作业文件(文件名/etc/init/test.conf):

description "test"
start on test
console owner
kill timeout 5
task
script
  /bin/echo Gotcha...
end script

我的目标是在执行initctl emit test或时看到文本“ Gotcha ...” initctl start test。但这不起作用。

到目前为止我尝试过的是:

  • “控制台输出”而不是“控制台所有者”
  • “ exec / bin / echo Gotcha ...”而不是脚本...结束脚本

Answers:


8

由于init(pid 1)正在运行服务(没有stdout / stderr),而不是您的Shell(与较早的/etc/init.d-style脚本一样),因此目前无法查看生成的输出。(经常要求使用此功能,该功能在Upstart要做的事情上。)

要解决此问题,我建议在作业本身开始时强制输出重定向:

script
    exec >/var/log/test.debug 2>&1
    echo Gotcha...
end script

16

从12.04开始(可能在之前),默认情况下,upstart将使用作业的任何输出记录到/ var / log / upstart /下的文件

Upstart的最新文档(在Cookbook上)

然后,您可以拖尾该文件以查看正在写入该文件的所有新文本。

例如:

tail -f /var/log/upstart/test.log & # tail the output
initctl emit test
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.