How to connect to a remote server using ssh and get information

I am trying to write a shell script using bash. I have several servers, and each server has several application launches. Each server also has special application scripts for checking / stopping / starting, etc. All I want to do is do ssh and connect to the remote server. Which I can also do successfully and exclude teams as well.

In some cases, I need to check the status of a process on a remote machine, this makes specific application scripts. But using my ssh, when I try to run this script, I do not receive any information (it starts, but the information is not transmitted). How to get information from a remote host and display it on a local host here.

Any help on this is really appreciated.

Regards, Senny

+4
source share
1 answer

You can run remote commands and get results locally by passing the command as a string in ssh.

In a script, you can:

CMD_OUT=$(ssh user@remote _host "/path/to/script argument") 

The command will be run remotely, and the output repository will be in the variable CMD_OUT . Then you can parse the output in a script to get the results you need.

To make it easier to use your script, you can configure passwordless ssh , so you do not need to enter a password every time the script tries to run a remote command.

+7
source

Source: https://habr.com/ru/post/1338233/


All Articles