Title: How to capture ALL output from 'killall' command in a script?
Tags: bash
Question: I originally had a 'killall' command redirect the output to a file and got this on three separate runs:
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&gt;&amp;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.
How do I capture all the output?
Thanks.
Comment: The script is being run via launchd and I redirect to the file there. Are you suggesting that the missing info will appear if I redirect inside the script?

Comment: You can also echo the output to the file instead


Here is another answer: You can use the option -v, --verbose in order to list the processes which received the issued signal. (See man killall)
-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&gt;&amp;1)
echo "$d$r"
exit 0
Replacing osascript with sleep gives me the following output:
2017-08-21 17:14:30 : Killed sleep(12493) with signal 15
Comment for this answer: Thanks. I've made the change. Waiting for osascript to misbehave and stay running after script finishes, which it does randomly (hence the need to kill it). I run the kill 1 minute before running the main script, which runs every 15 minutes.
Comment for this answer: Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:08/21/17', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<bash>', 'Title': "How to capture ALL output from 'killall' command in a script?", 'ViewCount': 347, 'id': 45799265, 'user_AboutMe': "<p>Retired Software Engineer. Currently interested in automating a bunch of tasks using Apple's JXA.</p>\n", 'user_AccountId': 11241283.0, 'user_DisplayName': 'Crashmeister', 'user_Reputation': 337.0, 'user_Views': 23.0, 'user_id': 8245469.0}}