0

I thought that my problem is trivial, but I cannot figure out, why my scripts only performing once in array.

I have a jenkins job (bash script). This job gathering hostnames and sends ssh commands, through script, using gathered info:

rm /tmp/hosts

docker exec -t tmgnt_consul_1 consul members -status=alive | grep -v  Node | awk '{print $1}' | cut -d : -f1 >> /tmp/hosts
sed -i '/someunnecessaryinfo/d' /tmp/hosts
echo >> /tmp/hosts

shopt -s lastpipe

while IFS= read -r line;  do 
echo "host is >>$line<<"; 
url="http://111.111.111.111:8500/v1/catalog/nodes"
term_IP=`curl -s $url | jq -r --arg Node "${line}" '.[] | select(.Node == "'${line}'" )|.Address' --raw-output`
echo $term_IP
sudo bash -x /home/rtm/t_mgnt/check_fw $term_IP 

done < /tmp/hosts

Second script:

#!/bin/bash

term_IP=$1

sudo sshpass -p 'some.pass' ssh -o StrictHostKeyChecking=no user@$term_IP "sudo test -d /root/nv9"
if [ $? != 0 ]; then
sudo sshpass -p 'some.pass' \
scp -n -o StrictHostKeyChecking=no -r /home/rtm/t_mgnt/nv9 user@$term_IP:
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user@$term_IP "sudo mv nv9 /root/"
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user@$term_IP "sudo dpkg -i /root/nv9/libudev0_175-0ubuntu9_amd64.deb"
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user@$term_IP "sudo /root/nv9/DetectValidator"
else
sudo sshpass -p 'some.pass' \
ssh -n -o StrictHostKeyChecking=no user@$term_IP "sudo /root/nv9/DetectValidator"
fi

The job is working fine, and returns correct values, but only for the first element of array.

PS - I already searched through this and other sites, and - following answer didn't help me - Shell script while read line loop stops after the first line (already "ssh -n -o"). Perhaps you can point me, what I missed.

Vasyl Stepulo
  • 1,493
  • 1
  • 23
  • 43

1 Answers1

1

Possibly this ssh call eats your input:

sudo sshpass -p 'some.pass' ssh -o StrictHostKeyChecking=no user@$term_IP "sudo test -d /root/nv9"
                            ^^^

Try adding -n.

Alex O
  • 7,746
  • 2
  • 25
  • 38