Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!