Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash select loop does not wait for input

I'm trying to make my life easier deploying something on 80+ machines. However not all of those machines run the same version of RHEL and there are subtle differences in the scripts that need to be run on them.

That's why I want get the release version first, and then choose which file to deploy on the machine.

The problem is the select loop won't wait for my input, it skips it completely and just moves on.

Here's the code I'm using

#!/bin/bash

version() {
    cat /etc/*-release | grep "release"
    select ver in "6" "7"
    do
        case $ver in
            6) echo "install for RH6"; break;;
            7) echo "install for RH7"; break;;
        esac
    done
}

while read srv
do
    ping -c 1 $srv
    ssh -n $srv "$(typeset -f); version"
done < $1

The ping is just there for test purposes

here's some sample output:

[email protected]'s password:
Red Hat Enterprise Linux Server release 7.1 (Maipo)
Red Hat Enterprise Linux Server release 7.1 (Maipo)

1) 6
2) 7
#? 
like image 225
Faryus Avatar asked Feb 17 '26 01:02

Faryus


1 Answers

the select can't read your input, because the input is already connected to the file $1 (done < $1 on the last line). Or actually the EOF or something is read.

If you need to interact with the script, you need to rewrite the while loop to something different, for example

for srv in "localhost"

works fine.

like image 132
Jakuje Avatar answered Feb 18 '26 23:02

Jakuje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!