Pass multiple commands over SSH and return output

Viewed 96

I am trying to write a short script that will SSH to a remote server, execute a few commands, and return the output prices and such, which I will parse locally.

So far, I am trying this, but it just hangs:

ssh user@server_name 'redis-cli; hmget IBM last updated; quit' > output.txt

The actual output will be 3 lines:

  1. "1234.56"
  2. "IBM"
  3. "11/13/2020 17:44:02"

Any way to run these commands and capture those 3 lines?

Thanks!

1 Answers

Ok so what I would do is write a script which does the following :

1)connects to sever And after makes sure it is connected (u can use a sleep command)

  1. Save output of commands to the file:

    Command1 > output.txt
    Command2 >> output.txt 
    

“>” is used to first create the file and “>>” to add more data to the same file

And so on

  1. send file back to local machine using scp (or any other tool you want)

In this case it’s really simple so command would be :

scp “output.txt” localuser@localserver:Destination/
Related