Here’s another version of my ssh-copy-id script this time using a text file containing a list of hosts. The hosts file should contain a single host per line.


export SSH_USER="user"
read -s PASSWORD

while read HOST; do
            export HOST;
            expect -c '
            set SSH_USER $env(SSH_USER)
            set HOST $env(HOST)
            set PASSWORD $env(PASSWORD)
            spawn ssh-copy-id $SSH_USER@$HOST
            expect {
                        "continue" {
                                    send "yes\n";
                        "assword:" {
                                    send "$PASSWORD\n";
            expect eof'
            echo "Done $HOST"
done < "$1"

Execute the script and pass the path to the text file as a parameter. i.e.

./ /path/to/host/list.txt;