shell script ssh command exit status

后端 未结 4 929
天命终不由人
天命终不由人 2020-12-31 01:34

In a loop in shell script, I am connecting to various servers and running some commands. For example

#!/bin/bash
FILENAME=$1
cat $FILENAME | while read HOST
         


        
4条回答
  •  不知归路
    2020-12-31 02:09

    An interesting approach would be to retrieve the whole output of each ssh command set in a local variable using backticks, or even seperate with a special charachter (for simplicity say ":") something like:

    export MYVAR=`ssh $HOST 'echo -n ${HOSTNAME}\:;pwd'`
    

    after this you can use awk to split MYVAR into your results and continue bash testing.

提交回复
热议问题