Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda