1

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user3846091
  • 1,625
  • 6
  • 24
  • 29
  • I might look at the `-n` and `-f` flags for `ssh`. It could be your ssh process is reading the rest of the input file that's directed to the while loop. I'm not sure you need the `-t` option here. – zerodiff Sep 29 '14 at 16:26

3 Answers3

1

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

Cyrus
  • 84,225
  • 14
  • 89
  • 153
0
  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.
Sammitch
  • 30,782
  • 7
  • 50
  • 77
0

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

ssh -t -t
bryn
  • 3,155
  • 1
  • 16
  • 15