Bash脚本不会ssh csv文件的所有条目 [英] Bash script does not ssh all the entries of a csv file

查看:74
本文介绍了Bash脚本不会ssh csv文件的所有条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用最新的修订包修补大量CENT OS计算机.我有以下bash脚本,它将csv文件作为输入,其中包含这些计算机的IP地址和密码.

I am trying to patch a bunch of CENT OS machines with the latest fix pack. I have the below bash script that takes csv file as a input which has the ip address and password for those machines.

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

The code works fine however, it would only work for the first row it does not seem to be working for the rest of the list as my output.txt only has the entry only for the first row host .

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" 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

hosts_test.cvs

10.xxx.xx.219,abcd~qY1
10.xxx.xx.226,l4~abcdefg
10.xxx.xx.221,l4@abcdefgh

端子输出

由于stdin不是终端,因此不会分配伪终端.

Pseudo-terminal will not be allocated because stdin is not a terminal.

推荐答案

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

Add at the end of your sshpass command </dev/null.

这篇关于Bash脚本不会ssh csv文件的所有条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆