Bash script does not ssh all the entries of a csv file

折月煮酒 提交于 2019-12-11 08:17:12

问题


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.

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

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

Terminal Output

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


回答1:


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




回答2:


  1. Add Defaults:username !requiretty to your /etc/sudoers config
  2. Get rid of -t from your ssh command
  3. Optional, but recommended: set up public key auth so you don't have your passwords lying around in text files.



回答3:


You can pass ssh another -t to force pty allocation:

ssh -t -t


来源:https://stackoverflow.com/questions/26103962/bash-script-does-not-ssh-all-the-entries-of-a-csv-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!