[問題] sshpass大量執行指令

看板LinuxDev作者 (~我愛夏天~)時間10年前 (2015/06/01 21:58), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/1
我有一個list與script如下 list.txt 10.10.1.1,gary,gary@123 10.10.1.2,belle,belle@123 ------------------------------------ #! /bin/bash while IFS="," read ip user user_passwd do ping -c 3 -w 3 $ip > /dev/null 2>&1 if [ $? != 0 ]; then echo $ip down! else echo $ip UP! fi done < list.txt 可以執行出我要的結果 但是,換成以下的方式 #! /bin/bash while IFS="," read ip user user_passwd do ping -c 3 -w 3 $ip > /dev/null 2>&1 if [ $? != 0 ]; then echo $ip down! else echo $ip UP! sshpass -p $user_passwd ssh -o StrictHostKeyChecking=no $user@$ip 'hostname' fi done < list.txt 出來的結果卻是 10.10.1.1 UP! localhost1 請教各位這有解決方式嗎? 謝謝 sshpass安裝參考 http://www.softwareprojects.com/resources/programming/t-ssh-no-password-without-any-private-keys-its-magi-1880.html -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.37.174.126 ※ 文章網址: https://www.ptt.cc/bbs/LinuxDev/M.1433167102.A.58B.html

06/02 02:25, , 1F
(1) while ... read ... 1<&5; do ... ; done 5< list.txt
06/02 02:25, 1F

06/02 02:25, , 2F
(2) sshpass ... ssh ... < /dev/null
06/02 02:25, 2F

06/02 02:27, , 3F
兩種方式任選一種應該都行得通.
06/02 02:27, 3F

06/02 15:19, , 4F
(1) 的 1<&5 手誤, 應為 0<&5 才對 :P
06/02 15:19, 4F
文章代碼(AID): #1LR6J-MB (LinuxDev)
文章代碼(AID): #1LR6J-MB (LinuxDev)