問題描述:
當在while循環中,使用ssh執行命令時,之後獲取第一行,例如第一行當IP。
解決方法:
1. 使用for 循環
2. 在ssh命令行中加入 -n 參數
以下是測試舉例:
#!/bin/bash
cat /tmp/.test.txt | while read i
do
ssh -n mysql@$i -o stricthostkeychecking=no "md5sum /home/mysql/mysql/etc/my.cnf"
done
#!/bin/bash
for i in `cat /tmp/.test.txt`
do
ssh mysql@$i -o stricthostkeychecking=no "md5sum /home/mysql/mysql/etc/my.cnf"
done