我下面有一个脚本,除了期望部分之外,都可以工作:
#!/bin/bash
#
invdir=/home/john/inventory
for file in $invdir/$1
do
if [ -z $1 ] || [ -z $2 ]
then
echo "You must enter a value: prod, dev, dr, or test AND the password of the env you entered"
exit 0
else
for host in `cat $file`
do
ssh-copy-id -i ~/.ssh/id_rsa.pub $host <<-EOF
expect "password:"
send "$2\n"
EOF
done
fi
done
我发现一个 Expect 脚本可以满足我的大部分需要:
#!/usr/bin/expect -f
spawn ssh-copy-id $argv
expect "password:"
send "your_password\n"
expect eof
to execute ./expect_script user@host1
我的问题是我对 bash 的了解不够,或者期望让这两个脚本在一个 bash 脚本或期望脚本下工作。
先感谢您....
一些注意事项:
for
<<-EOF
,因为使用非制表符来表示 EOF 单词太容易了。<<'EOF'
保护预期变量