开发者

how to connect to a remote server using ssh and getting the information

I'm trying to write a shell script using bash. I have multiple servers 开发者_运维知识库and each servers have multiple apps runnings on it. Each server also has specific app scripts to check/stop/start etc. All I want to do is that, do a ssh and connect to the remote server. Which I'm also able to do sucessfully and exceute the commands also..

In some instance I need to check some process status on a remote machine, the app sepecific scripts already does that. But using my ssh when i try to execute that script I dont get any info ( it gets executed but no info is passed ). How do i get the information from the remote host and display on the local host here.

Any help on this is really appreciated.

Regards, Senny


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

In your script, you can do:

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

The command will be run remotely and the output store in the CMD_OUT variable. You can then parse the output in your script to get the results you want.

To simplify usage of your script, you might want to set up passwordless ssh so you don't have to type your password each time the script tries to run a remote command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜