Submitting "ps" across multiple servers, output going to one text file

Dan

I'm trying to build a script that'll output all defunct processes across 66 redhat boxes to a single text file. I understand the principles of doing this on one box, but I'm not sure how to shoehorn that process into something that'll run on one box, but query several boxes.

So, I've found this little script:

for host in $(cat hosts.txt); do ssh "$host" "$command" >"output.$host"; done

I understand that I could essentially submit ps -ef | grep "defunct" as the $command, but I think any output file I create will be dropped onto the host it's running on.

I need to make this run from one box, storing the output on that one box, but containing the information for the other 65 boxes?

I believe we have passwordless ssh in place. My knowledge of Unix is sort of intermediate, I know bits of it because I'm using SAS.

Kusalananda

The redirection happens on the calling machine, not on the remote machine, so the result file will be local. Also, the grep does not need to run remotely:

while read -r host; do
    ssh "$host" ps -ef | grep "defunct" >"output.$host"
done <hosts.txt

This executes ps -ef on each host and grep will extract the defunct lines of output. The grep will run locally, not remotely. The result file, likewise, is created locally.

If you want a single output file:

while read -r host; do
    ssh "$host" ps -ef | grep "defunct"
done <hosts.txt >output.txt

Or even (for a single invocation of grep)

while read -r host; do
    ssh "$host" ps -ef 
done <hosts.txt | grep "defunct" >output.txt

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Synchronization xml file across multiple servers(machine)

Piping PS output into a Text file

Output of Python loop not going to text file

Output both ps and Date on one line, to a file?

Golang file and folder replication / mirroring across multiple servers

MySQL database across multiple servers

One domain multiple servers

How do you restrict specific content to only one column instead of going across multiple columns?

Share one file across multiple git repo to be updated by multiple users

Generate unique ID across multiple independent servers

How to manage websockets across multiple servers / workers

How to scale a trie across multiple servers

Java: synchronizing threads across multiple servers

Synchronized script execution across multiple servers

Scaling Socket.IO across multiple servers

Shared Varnish cache across multiple servers

Using sed command in for loop across multiple servers

Bash Script to Transfer File across Two Servers

ansible - ensure content of file is the same across servers

combine multiple text files into one text file?

Submitting multiple forms with one button

Submitting multiple variables with one input

How to reference a variable in one file, and be able to use across multiple files?

Replace file text between two words across multiple lines

source multiple files and output one file

Read multiple file in python and generate one output

Import multiple files and then output the calculation into one file

Saving multiple output in a text file in c++

Multiple jenkins servers on one server