Showing posts with label Bash Delete entries from CSV file. Show all posts
Showing posts with label Bash Delete entries from CSV file. Show all posts

Thursday, 30 August 2018

The Bash script does not delete all entries from a csv file


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.

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