Failed to run scripts in multiple remote host by ssh

前端 未结 3 1197
轻奢々
轻奢々 2021-01-24 21:27

I write a deployAll.sh, which read ip_host.list line by line, then add group for all the remote hosts,

when I run: sh deployAll.sh

results:

Gro         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 21:36

    Without the ssh command (which wouldn't make sense on my network), I get the expected output so I suspect that the ssh command is swallowing the remaining standard input. You should use the -n flag to prevent ssh from reading from stdin (equivalent to redirecting stdin from /dev/null):

    ssh -n "${ipandhost[0]}" "groupadd -g 1011 test"
    

    or

    ssh "${ipandhost[0]}" "groupadd -g 1011 test" < /dev/null
    

    See also How to keep script from swallowing all of stdin?

提交回复
热议问题