【问题标题】:Bash script does not ssh all the entries of a csv fileBash 脚本不会对 csv 文件的所有条目进行 ssh
【发布时间】:2014-09-29 15:53:31
【问题描述】:

我正在尝试使用最新的修复包修补一堆 CENT OS 机器。我有以下 bash 脚本,它将 csv 文件作为输入,其中包含这些机器的 IP 地址和密码。

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

补丁.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

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

终端输出

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

【问题讨论】:

  • 我可能会查看ssh-n-f 标志。可能是您的 ssh 进程正在读取指向 while 循环的输入文件的其余部分。我不确定您是否需要 -t 选项。

标签: linux bash centos shellshock-bash-bug


【解决方案1】:

在您的 sshpass 命令末尾添加 &lt;/dev/null

【讨论】:

    【解决方案2】:
    1. Defaults:username !requiretty 添加到您的/etc/sudoers 配置中
    2. 从您的 ssh 命令中删除 -t
    3. 可选,但建议:设置公钥身份验证,这样您的密码就不会出现在文本文件中。

    【讨论】:

      【解决方案3】:

      您可以通过 ssh 另一个 -t 来强制分配 pty:

      ssh -t -t
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-16
        • 2017-04-08
        • 1970-01-01
        • 1970-01-01
        • 2021-10-28
        • 1970-01-01
        • 2012-12-15
        相关资源
        最近更新 更多