2014-09-29 71 views
1

我想用最新的修复包修补一大堆CENT OS机器。我有下面的bash脚本,它将csv文件作为具有这些机器的ip地址和密码的输入。Bash脚本不会ssh所有的csv文件的条目

但是,它的代码工作正常,它只适用于第一行,它似乎没有为列表的其余部分工作,因为我的output.txt只有第一行主机的条目。

patch.sh

INPUT=hosts_test.cvs 
OLDIFS=$IFS 
IFS=, 
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } 
while read privateip password 
do 

sshpass -p$password ssh -t -o "StrictHostKeyChecking no" [email protected]$privateip " 

hostname 
hostname -I --all-ip-addresses 
sudo yum -y update bash 
env x='() { :;}; echo vulnerable' bash -c \"echo If you see the word vulnerable above, then you are vulnerable to shellshock\" 
echo "" 
exit 

" >> output.txt 

done < $INPUT 
IFS=$OLDIFS 

hosts_test.cvs

10.xxx.xx.219,abcd~qY1 
10.xxx.xx.226,l4~abcdefg 
10.xxx.xx.221,[email protected] 

端子输出

伪终端将不被分配,因为标准输入不是终端。

+0

我可能看的'ssh'的'-n'和'-f'标志。这可能是你的ssh进程正在读取指向while循环的输入文件的其余部分。我不确定你需要'-t'选项。 – zerodiff 2014-09-29 16:26:28

回答

0

添加在您的sshpass命令</dev/null的末尾。

0
  1. 添加Defaults:username !requiretty/etc/sudoers配置
  2. 从你的ssh命令
  3. 可选摆脱-t,但建议:设立公共密钥身份验证,所以你没有你的密码趴在文本文件中周围。
0

你可以通过SSH另一-t强制分配pty:

ssh -t -t 
相关问题