re-write a string with text and numbers onto a newline and insert text
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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
linux bash shell-script shell string
add a comment |Â
up vote
0
down vote
favorite
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
linux bash shell-script shell string
I don't get it. Please add a proper example and result. For the given examples, the answer is valid. Please properly format you text so that we don't have to guess what you mean.
â RoVo
Aug 13 at 11:45
Why is the last line outputted if you grep forrrcp
?
â Kusalananda
Aug 13 at 11:46
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
linux bash shell-script shell string
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
linux bash shell-script shell string
linux bash shell-script shell string
edited Aug 13 at 14:49
asked Aug 13 at 10:55
SaSa2929
11
11
I don't get it. Please add a proper example and result. For the given examples, the answer is valid. Please properly format you text so that we don't have to guess what you mean.
â RoVo
Aug 13 at 11:45
Why is the last line outputted if you grep forrrcp
?
â Kusalananda
Aug 13 at 11:46
add a comment |Â
I don't get it. Please add a proper example and result. For the given examples, the answer is valid. Please properly format you text so that we don't have to guess what you mean.
â RoVo
Aug 13 at 11:45
Why is the last line outputted if you grep forrrcp
?
â Kusalananda
Aug 13 at 11:46
I don't get it. Please add a proper example and result. For the given examples, the answer is valid. Please properly format you text so that we don't have to guess what you mean.
â RoVo
Aug 13 at 11:45
I don't get it. Please add a proper example and result. For the given examples, the answer is valid. Please properly format you text so that we don't have to guess what you mean.
â RoVo
Aug 13 at 11:45
Why is the last line outputted if you grep for
rrcp
?â Kusalananda
Aug 13 at 11:46
Why is the last line outputted if you grep for
rrcp
?â Kusalananda
Aug 13 at 11:46
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
please try this,
I have saved the given sample output in file /tmp/test.txt.
xargs -n 2 | sed 's/^/Hostname1 /'
-n
means maximum arguments per line.
For example;
cat /tmp/test.txt | xargs -n 2 | sed 's/^/Hostname1 /g'
Hostname1 rrcpd 17
Hostname1 rrcpd 0
Hostname1 Cheese 3
Hostname1 cakes 8
Hostname1 Cats 9
Hostname1 dogs 3
There is only one match of^
per line, so using/g
is not needed.
â Kusalananda
Aug 13 at 12:02
add a comment |Â
up vote
0
down vote
The only reason you would see the type of data that you show (more than two fields per line in the output of the ssh
command) is when you collect the output of your ssh
+ps
call into a variable and then output it without quoting it properly, as in output=$(ssh ...)
followed by echo $output
instead of echo "$output"
. Luckily, you don't need to collect the data in a variable at all.
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
awk -v host="$remote" '/rrcp/ print host, $1, $2 '
done <hosts.txt
Here, awk
is reading directly from the ssh
command and also does the work originally done by grep
in your code. It assumes that it will get lines with two fields and will prefix each pair of fields with the given hostname (read from hosts.txt
).
Alternatively,
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
sed "s/^/$remote /"
done <hosts.txt
Here, we simply prefix each line with the hostname read from the text file.
I want to read the output in of a single line of string and numbers which is normally process name followed by a number which is the core. Sometimes its a single text and number and sometimes it return 2, 3 or 4 processes with text followed by number. My aim is to get this command output ps -eo comm,lastcpu and split each text number, text number ........ to multiple rows and label each row with a host name followed by text number.
â SaSa2929
Aug 13 at 12:21
@SaSa2929 Did you actually test the code I posted? Theps
utility will only ever output two columns. The only reason you find yourself working with lines of more columns is that youecho
an unquoted variable.
â Kusalananda
Aug 13 at 12:25
Thank you, it works, almost, Tried it, it only reads the first host, how do I get it to loop to the next host?
â SaSa2929
Aug 13 at 12:34
@SaSa2929 Ah, I forgot,ssh
would eat the data from the input file. Usessh -n
. I will update the answer...
â Kusalananda
Aug 13 at 12:38
I have modified it to use a for loop and it works now and returns all the processes, how is it possible to go one step further and provide a list of processes that I am interested in and ignore all others. I can defind the processes in an array of some sort, or include list, all others are exluded. #!/bin/bash for remote in $(cat ssh_hosts2.txt) do ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu | sed "s/^/$remote /" done
â SaSa2929
Aug 13 at 14:51
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
please try this,
I have saved the given sample output in file /tmp/test.txt.
xargs -n 2 | sed 's/^/Hostname1 /'
-n
means maximum arguments per line.
For example;
cat /tmp/test.txt | xargs -n 2 | sed 's/^/Hostname1 /g'
Hostname1 rrcpd 17
Hostname1 rrcpd 0
Hostname1 Cheese 3
Hostname1 cakes 8
Hostname1 Cats 9
Hostname1 dogs 3
There is only one match of^
per line, so using/g
is not needed.
â Kusalananda
Aug 13 at 12:02
add a comment |Â
up vote
2
down vote
please try this,
I have saved the given sample output in file /tmp/test.txt.
xargs -n 2 | sed 's/^/Hostname1 /'
-n
means maximum arguments per line.
For example;
cat /tmp/test.txt | xargs -n 2 | sed 's/^/Hostname1 /g'
Hostname1 rrcpd 17
Hostname1 rrcpd 0
Hostname1 Cheese 3
Hostname1 cakes 8
Hostname1 Cats 9
Hostname1 dogs 3
There is only one match of^
per line, so using/g
is not needed.
â Kusalananda
Aug 13 at 12:02
add a comment |Â
up vote
2
down vote
up vote
2
down vote
please try this,
I have saved the given sample output in file /tmp/test.txt.
xargs -n 2 | sed 's/^/Hostname1 /'
-n
means maximum arguments per line.
For example;
cat /tmp/test.txt | xargs -n 2 | sed 's/^/Hostname1 /g'
Hostname1 rrcpd 17
Hostname1 rrcpd 0
Hostname1 Cheese 3
Hostname1 cakes 8
Hostname1 Cats 9
Hostname1 dogs 3
please try this,
I have saved the given sample output in file /tmp/test.txt.
xargs -n 2 | sed 's/^/Hostname1 /'
-n
means maximum arguments per line.
For example;
cat /tmp/test.txt | xargs -n 2 | sed 's/^/Hostname1 /g'
Hostname1 rrcpd 17
Hostname1 rrcpd 0
Hostname1 Cheese 3
Hostname1 cakes 8
Hostname1 Cats 9
Hostname1 dogs 3
edited Aug 13 at 12:06
answered Aug 13 at 11:04
EBIN GLADSON
656
656
There is only one match of^
per line, so using/g
is not needed.
â Kusalananda
Aug 13 at 12:02
add a comment |Â
There is only one match of^
per line, so using/g
is not needed.
â Kusalananda
Aug 13 at 12:02
There is only one match of
^
per line, so using /g
is not needed.â Kusalananda
Aug 13 at 12:02
There is only one match of
^
per line, so using /g
is not needed.â Kusalananda
Aug 13 at 12:02
add a comment |Â
up vote
0
down vote
The only reason you would see the type of data that you show (more than two fields per line in the output of the ssh
command) is when you collect the output of your ssh
+ps
call into a variable and then output it without quoting it properly, as in output=$(ssh ...)
followed by echo $output
instead of echo "$output"
. Luckily, you don't need to collect the data in a variable at all.
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
awk -v host="$remote" '/rrcp/ print host, $1, $2 '
done <hosts.txt
Here, awk
is reading directly from the ssh
command and also does the work originally done by grep
in your code. It assumes that it will get lines with two fields and will prefix each pair of fields with the given hostname (read from hosts.txt
).
Alternatively,
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
sed "s/^/$remote /"
done <hosts.txt
Here, we simply prefix each line with the hostname read from the text file.
I want to read the output in of a single line of string and numbers which is normally process name followed by a number which is the core. Sometimes its a single text and number and sometimes it return 2, 3 or 4 processes with text followed by number. My aim is to get this command output ps -eo comm,lastcpu and split each text number, text number ........ to multiple rows and label each row with a host name followed by text number.
â SaSa2929
Aug 13 at 12:21
@SaSa2929 Did you actually test the code I posted? Theps
utility will only ever output two columns. The only reason you find yourself working with lines of more columns is that youecho
an unquoted variable.
â Kusalananda
Aug 13 at 12:25
Thank you, it works, almost, Tried it, it only reads the first host, how do I get it to loop to the next host?
â SaSa2929
Aug 13 at 12:34
@SaSa2929 Ah, I forgot,ssh
would eat the data from the input file. Usessh -n
. I will update the answer...
â Kusalananda
Aug 13 at 12:38
I have modified it to use a for loop and it works now and returns all the processes, how is it possible to go one step further and provide a list of processes that I am interested in and ignore all others. I can defind the processes in an array of some sort, or include list, all others are exluded. #!/bin/bash for remote in $(cat ssh_hosts2.txt) do ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu | sed "s/^/$remote /" done
â SaSa2929
Aug 13 at 14:51
add a comment |Â
up vote
0
down vote
The only reason you would see the type of data that you show (more than two fields per line in the output of the ssh
command) is when you collect the output of your ssh
+ps
call into a variable and then output it without quoting it properly, as in output=$(ssh ...)
followed by echo $output
instead of echo "$output"
. Luckily, you don't need to collect the data in a variable at all.
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
awk -v host="$remote" '/rrcp/ print host, $1, $2 '
done <hosts.txt
Here, awk
is reading directly from the ssh
command and also does the work originally done by grep
in your code. It assumes that it will get lines with two fields and will prefix each pair of fields with the given hostname (read from hosts.txt
).
Alternatively,
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
sed "s/^/$remote /"
done <hosts.txt
Here, we simply prefix each line with the hostname read from the text file.
I want to read the output in of a single line of string and numbers which is normally process name followed by a number which is the core. Sometimes its a single text and number and sometimes it return 2, 3 or 4 processes with text followed by number. My aim is to get this command output ps -eo comm,lastcpu and split each text number, text number ........ to multiple rows and label each row with a host name followed by text number.
â SaSa2929
Aug 13 at 12:21
@SaSa2929 Did you actually test the code I posted? Theps
utility will only ever output two columns. The only reason you find yourself working with lines of more columns is that youecho
an unquoted variable.
â Kusalananda
Aug 13 at 12:25
Thank you, it works, almost, Tried it, it only reads the first host, how do I get it to loop to the next host?
â SaSa2929
Aug 13 at 12:34
@SaSa2929 Ah, I forgot,ssh
would eat the data from the input file. Usessh -n
. I will update the answer...
â Kusalananda
Aug 13 at 12:38
I have modified it to use a for loop and it works now and returns all the processes, how is it possible to go one step further and provide a list of processes that I am interested in and ignore all others. I can defind the processes in an array of some sort, or include list, all others are exluded. #!/bin/bash for remote in $(cat ssh_hosts2.txt) do ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu | sed "s/^/$remote /" done
â SaSa2929
Aug 13 at 14:51
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The only reason you would see the type of data that you show (more than two fields per line in the output of the ssh
command) is when you collect the output of your ssh
+ps
call into a variable and then output it without quoting it properly, as in output=$(ssh ...)
followed by echo $output
instead of echo "$output"
. Luckily, you don't need to collect the data in a variable at all.
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
awk -v host="$remote" '/rrcp/ print host, $1, $2 '
done <hosts.txt
Here, awk
is reading directly from the ssh
command and also does the work originally done by grep
in your code. It assumes that it will get lines with two fields and will prefix each pair of fields with the given hostname (read from hosts.txt
).
Alternatively,
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
sed "s/^/$remote /"
done <hosts.txt
Here, we simply prefix each line with the hostname read from the text file.
The only reason you would see the type of data that you show (more than two fields per line in the output of the ssh
command) is when you collect the output of your ssh
+ps
call into a variable and then output it without quoting it properly, as in output=$(ssh ...)
followed by echo $output
instead of echo "$output"
. Luckily, you don't need to collect the data in a variable at all.
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
awk -v host="$remote" '/rrcp/ print host, $1, $2 '
done <hosts.txt
Here, awk
is reading directly from the ssh
command and also does the work originally done by grep
in your code. It assumes that it will get lines with two fields and will prefix each pair of fields with the given hostname (read from hosts.txt
).
Alternatively,
while read remote; do
ssh -n -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu |
sed "s/^/$remote /"
done <hosts.txt
Here, we simply prefix each line with the hostname read from the text file.
edited Aug 13 at 12:38
answered Aug 13 at 11:48
Kusalananda
106k14209327
106k14209327
I want to read the output in of a single line of string and numbers which is normally process name followed by a number which is the core. Sometimes its a single text and number and sometimes it return 2, 3 or 4 processes with text followed by number. My aim is to get this command output ps -eo comm,lastcpu and split each text number, text number ........ to multiple rows and label each row with a host name followed by text number.
â SaSa2929
Aug 13 at 12:21
@SaSa2929 Did you actually test the code I posted? Theps
utility will only ever output two columns. The only reason you find yourself working with lines of more columns is that youecho
an unquoted variable.
â Kusalananda
Aug 13 at 12:25
Thank you, it works, almost, Tried it, it only reads the first host, how do I get it to loop to the next host?
â SaSa2929
Aug 13 at 12:34
@SaSa2929 Ah, I forgot,ssh
would eat the data from the input file. Usessh -n
. I will update the answer...
â Kusalananda
Aug 13 at 12:38
I have modified it to use a for loop and it works now and returns all the processes, how is it possible to go one step further and provide a list of processes that I am interested in and ignore all others. I can defind the processes in an array of some sort, or include list, all others are exluded. #!/bin/bash for remote in $(cat ssh_hosts2.txt) do ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu | sed "s/^/$remote /" done
â SaSa2929
Aug 13 at 14:51
add a comment |Â
I want to read the output in of a single line of string and numbers which is normally process name followed by a number which is the core. Sometimes its a single text and number and sometimes it return 2, 3 or 4 processes with text followed by number. My aim is to get this command output ps -eo comm,lastcpu and split each text number, text number ........ to multiple rows and label each row with a host name followed by text number.
â SaSa2929
Aug 13 at 12:21
@SaSa2929 Did you actually test the code I posted? Theps
utility will only ever output two columns. The only reason you find yourself working with lines of more columns is that youecho
an unquoted variable.
â Kusalananda
Aug 13 at 12:25
Thank you, it works, almost, Tried it, it only reads the first host, how do I get it to loop to the next host?
â SaSa2929
Aug 13 at 12:34
@SaSa2929 Ah, I forgot,ssh
would eat the data from the input file. Usessh -n
. I will update the answer...
â Kusalananda
Aug 13 at 12:38
I have modified it to use a for loop and it works now and returns all the processes, how is it possible to go one step further and provide a list of processes that I am interested in and ignore all others. I can defind the processes in an array of some sort, or include list, all others are exluded. #!/bin/bash for remote in $(cat ssh_hosts2.txt) do ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu | sed "s/^/$remote /" done
â SaSa2929
Aug 13 at 14:51
I want to read the output in of a single line of string and numbers which is normally process name followed by a number which is the core. Sometimes its a single text and number and sometimes it return 2, 3 or 4 processes with text followed by number. My aim is to get this command output ps -eo comm,lastcpu and split each text number, text number ........ to multiple rows and label each row with a host name followed by text number.
â SaSa2929
Aug 13 at 12:21
I want to read the output in of a single line of string and numbers which is normally process name followed by a number which is the core. Sometimes its a single text and number and sometimes it return 2, 3 or 4 processes with text followed by number. My aim is to get this command output ps -eo comm,lastcpu and split each text number, text number ........ to multiple rows and label each row with a host name followed by text number.
â SaSa2929
Aug 13 at 12:21
@SaSa2929 Did you actually test the code I posted? The
ps
utility will only ever output two columns. The only reason you find yourself working with lines of more columns is that you echo
an unquoted variable.â Kusalananda
Aug 13 at 12:25
@SaSa2929 Did you actually test the code I posted? The
ps
utility will only ever output two columns. The only reason you find yourself working with lines of more columns is that you echo
an unquoted variable.â Kusalananda
Aug 13 at 12:25
Thank you, it works, almost, Tried it, it only reads the first host, how do I get it to loop to the next host?
â SaSa2929
Aug 13 at 12:34
Thank you, it works, almost, Tried it, it only reads the first host, how do I get it to loop to the next host?
â SaSa2929
Aug 13 at 12:34
@SaSa2929 Ah, I forgot,
ssh
would eat the data from the input file. Use ssh -n
. I will update the answer...â Kusalananda
Aug 13 at 12:38
@SaSa2929 Ah, I forgot,
ssh
would eat the data from the input file. Use ssh -n
. I will update the answer...â Kusalananda
Aug 13 at 12:38
I have modified it to use a for loop and it works now and returns all the processes, how is it possible to go one step further and provide a list of processes that I am interested in and ignore all others. I can defind the processes in an array of some sort, or include list, all others are exluded. #!/bin/bash for remote in $(cat ssh_hosts2.txt) do ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu | sed "s/^/$remote /" done
â SaSa2929
Aug 13 at 14:51
I have modified it to use a for loop and it works now and returns all the processes, how is it possible to go one step further and provide a list of processes that I am interested in and ignore all others. I can defind the processes in an array of some sort, or include list, all others are exluded. #!/bin/bash for remote in $(cat ssh_hosts2.txt) do ssh -q -o StrictHostKeyChecking=yes "$remote" ps -eo comm,lastcpu | sed "s/^/$remote /" done
â SaSa2929
Aug 13 at 14:51
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462274%2fre-write-a-string-with-text-and-numbers-onto-a-newline-and-insert-text%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I don't get it. Please add a proper example and result. For the given examples, the answer is valid. Please properly format you text so that we don't have to guess what you mean.
â RoVo
Aug 13 at 11:45
Why is the last line outputted if you grep for
rrcp
?â Kusalananda
Aug 13 at 11:46