Shell结合Expect实现自动输入密码

Shell结合Expect自动输入密码示例

 1 #!/bin/bash
 2 
 3 cd /data/live
 4 
 5 /usr/bin/expect <<-EOF
 6 spawn git clone "ssh://xxxxxxxxxxxx"
 7 expect "*passphrase*"
 8 send "passwordhere
"
 9 expect eof
10 EOF
11 
12 time=`/bin/date "+%Y%m%d%H%M%S"`
13 cd dir1 && tar czf /data/www/dir2_$time.tar.gz dir2
14 cd .. && rm -rf dir1
15 if [ $? -eq 0 ]
16 then
17     echo "Download here: http://10.13.38.22/dir2_"$time".tar.gz"
18 else
19     echo "Download Error!"
20 fi
作者:Standby一生热爱名山大川、草原沙漠,还有妹子
出处:http://www.cnblogs.com/standby/

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/standby/p/6791748.html