0

I would like to know how to capture the output of this command into a variable

ssh -q $ssh_host 'ps -eo comm,lastcpu'

Once the information is captured, I want to check the variable if it returned more then one result and label it

Example

rpciod/0 0 rpciod/1 1 rpciod/2 2 rpciod/3 3

After processing I want the output to be

it adds the hostname and puts the output on separate line, removing /1 /2 if it find it

Hostname1 being the value of $ssh_host

hostname1 rpciod 0 hostname1 rpciod 1 hostname1 rpciod 2 hostname1 rpciod 3

jasonwryan
  • 73,126
  • 1
    variable=$(ssh -q $ssh_host 'ps -eo comm,lastcpu') – Raman Sailopal Aug 09 '18 at 14:46
  • I have tried that but it seems not to work, I need to catch the output and amend it as per above table. – SaSa2929 Aug 09 '18 at 14:51
  • Once you have the variable filled with the output from the command, you can process it with tools such as sed, awk, etc. – lgeorget Aug 09 '18 at 15:34
  • 1
    @lgeorget If further processing of the output is to be done, you should not put it into a variable but pipe it to the next processing stage. – Kusalananda Aug 09 '18 at 19:03
  • Please expand this question by stating you've tried what's in the dupe, describe exactly what you did, what output you were expecting, and what you got and I'll support a re-open vote. – Shadur-don't-feed-the-AI Aug 10 '18 at 06:57

1 Answers1

0

You do it the same as with any other command:

VAR=$(ssh -q $ssh_host 'ps -eo comm,lastcpu')
RalfFriedl
  • 8,981