简体   繁体   English

如何从脚本中的“ killall”命令捕获所有输出?

[英]How to capture ALL output from 'killall' command in a script?

I originally had a 'killall' command redirect the output to a file and got this on three separate runs: 我最初有一个“ killall”命令,将输出重定向到文件,并在三个单独的运行中得到它:

No matching processes belonging to you were found
kill -TERM 7370
No matching processes belonging to you were found

I wanted a timestamp, so I changed my script to this: 我想要一个时间戳,所以我将脚本更改为此:

d=$(date "+%Y-%m-%d %H:%M:%S : ")
r=$(killall osascript 2>&1)
echo "$d$r"
exit 0

and now I get this (three separate runs): 现在我得到了(三个单独的运行):

2017-08-18 16:14:01 : No matching processes belonging to you were found
2017-08-18 16:29:01 :
2017-08-18 16:44:02 : No matching processes belonging to you were found

This is missing the kill -TERM nnnn detail. 这缺少kill -TERM nnnn详细信息。

How do I capture all the output? 如何捕获所有输出?

Thanks. 谢谢。

You can use the option -v, --verbose in order to list the processes which received the issued signal. 您可以使用选项-v, --verbose来列出接收已发出信号的进程。 (See man killall ) (请参见man killall

-v, --verbose -v,--verbose

Report if the signal was successfully sent. 报告信号是否已成功发送。

Hence, your script should look like this: 因此,您的脚本应如下所示:

#!/bin/bash
d=$(date "+%Y-%m-%d %H:%M:%S : ")
r=$(killall -v osascript 2>&1)
echo "$d$r"
exit 0

Replacing osascript with sleep gives me the following output: sleep替换osascript可得到以下输出:

2017-08-21 17:14:30 : Killed sleep(12493) with signal 15

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

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