shell中expect用法

#!/bin/bash
workdir="/data/opr/clean_account"
hostslist="/data/opr/clean_account/hosts"
ip=`cat /data/opr/clean_account/hosts`
password=123456
eval `ssh-agent`
/usr/bin/expect <<EOF
spawn ssh-add -k "/root/.ssh/id_rsa"
expect {
"Enter passphrase for /root/.ssh/id_rsa:" { send "$password\r" }
}
expect -timeout -1 eof
EOF
ansible-playbook -i $hostslist $workdir/clean_paic.yml

目的:在shell中交互ssh key密码,再执行ansible-playbook

 

posted @ 2020-07-16 10:05  litton888  阅读(845)  评论(0)    收藏  举报