In Short, I want to split single line output string into multiple rows and label each raw with the hostname.
Hostname ProcessName CPUCore
output=$(ssh -q -o "StrictHostKeyChecking yes" $ssh_host 'ps -eo comm,lastcpu | grep rrcp')
How to insert loop through a return out put that looks like.
rrcpd 17 rrcpd 0
and re-write as
Hostname1 rrcpd 17
Hostname1 rrcpd 0
Note
The numbers can very from 0-32
Hostname is a variable string $myhost
The text does change, meaning it is not strictly rrcpd, it could be e.g.
rrcpd 17 rrcpd 0
Cheese 3 cakes 8
Cats 9 dogs 3
Command that run on each host
output=$(ssh -q -o "StrictHostKeyChecking yes" $ssh_host 'ps -eo comm,lastcpu | grep rrcp')
The output can come back with 3-5 process when I remove the grep, hence I want to be able to split each output and add the hostname to the raw to label each output. I am checking what processes are running on each host.
rrcpd 0 rrcp_mon.sh 24
rrcpd 0
rrcpd 0
rrcpd 0 rrcpd 1
rrcpd 0 rrcpd 0 rrcp_mon 24 rrcp_mon 24
rrcpd 0
rrcpd 0
rrcpd 17 rrcpd 0
ard 9 ssh 32 httpd 21 bax 22
I have modified the provided below and managed to get it to work
#!/bin/bash
for remote in $(cat ssh_hosts2.txt)
do
ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
sed "s/^/$remote /"
done
rrcp
?