Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
Running Vagrant SSH causes BASH loop to terminate prematurely

I have a bash script that fetches running selenium nodes, grabs their ID, and SSHs into them to perform configuration tasks.

#!/bin/bash

# retrieve list of running vagrant machines, filter them to selenium nodes, and
# process provisioning for each
vagrant global-status --prune | grep "selenium_node" | while read -ra line ; do
    echo -e "\033[32mBEGININNG ${line[1]} PROVISIONING\033[37m"

    # adding this statement causes the loop to exit after 1 iteration
    vagrant ssh ${line[0]} -- "
        echo 'it runs'
    "

    echo -e "\033[32mEND ${line[1]} PROVISION\033[37m"
done

My problem is that running vagrant ssh causes the loop to terminate after the first iteration. I confirmed this by removing 'vagrant ssh' and the results were that both the BEGINNING and END echo commands ran successfully for every iteration (in my case - two iterations).

What's stranger is that the loop DOES complete it's first iteration (as evinced by the END echo line completing), it just doesn't run any further iterations.

Also, I've confirmed that it's not just neglecting to show the output from the other iterations. It never performs any operations on the other machines.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

ssh - including vagrant ssh - consumes standard input, so if you run it inside a while read loop, it won't leave anything for the next loop iteration to read.

You can fix that by either telling ssh not to read standard input (ssh -n) or by using a different construct than while read. In this case, since vagrant ssh doesn't support the -n option, I suggest running it with its input redirected from /dev/null:

</dev/null vagrant ssh ${line[0]} -- "
    echo 'it runs'
"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda