3

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
#? 
1
  • 1
    You define your function in the shell running on your local machine. The remote host will not know about it. Commented Jan 15, 2016 at 14:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You can use a different file descriptor for the while read loop: while read -u3 -r srv; do ...; done 3<"$1" -- then select is free to use stdin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.