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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM