小编典典

Bash脚本不会ssh csv文件的所有条目

linux

我正在尝试使用最新的修订包修补一堆CENT OS计算机。我有下面的bash脚本,它将csv文件作为输入,这些文件具有这些计算机的ip地址和密码。

该代码运行良好,但是,它仅适用于第一行,而对于其余列表似乎无效,因为我的output.txt仅具有第一行host的条目。

补丁

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" user123@$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,l4@abcdefgh

终端输出

因为stdin不是终端,所以不会分配伪终端。


阅读 247

收藏
2020-06-07

共1个答案

小编典典

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

2020-06-07