[問題] sshpass大量執行指令
我有一個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
06/02 02:25, 1F
→
06/02 02:25, , 2F
06/02 02:25, 2F
→
06/02 02:27, , 3F
06/02 02:27, 3F
→
06/02 15:19, , 4F
06/02 15:19, 4F
LinuxDev 近期熱門文章
PTT數位生活區 即時熱門文章