while read does not work in Unix shell script

0

I am programming a script and using while read twice it does 1 only once:

un=$(echo $LOGNAME | tr '[A-Z]' '[a-z]')
grep -v '^#' nodeteste.txt > auxiliar.txt
while read line
do
  ssh "$un@$line" "cat arquivo" > arquivo.externo
  cut -d "," -f 1 arquivo.externo > arquivo.externo.cut
  uniq arquivo.externo.cut > arquivo.externo.cut.uniq
  while read line2
  do
   valor=$(grep -c "$line2 " arquivo.base)
   if [ $valor -eq 0 ]; then
     echo $line >> arquivo.base.diferente
     echo $line2 >> arquivo.base.diferente
     grep -i "$line2," arquivo.externo >> arquivo.base.diferente
     echo $line $line2 $valor "eh diferente"
   fi
  done < arquivo.externo.cut.uniq
done < auxiliar.txt
rm auxiliar.txt

It runs the first while only once, I'm suspicious that it has lost stdin / out at some point !! Someone could give some tips !!

    
asked by anonymous 13.02.2018 / 18:59

1 answer

0

I found the problem, ssh uses stdin causing the problem of stopping the 1 loop after only 1 passed, when I use the -n option it redirects stdin by stopping the problem.

Problem source:

ssh "$ un @ line" "cat file" > external file

Works source:

ssh -n "$ un @ line" "cat file" > external file

Manual SSH: -n Redirects stdin from / dev / null (prevents reading stdin).

    
14.02.2018 / 17:26