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\n"
 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

 

posted @ 2017-05-01 13:19  lixin[at]hitwh  阅读(623)  评论(0编辑  收藏  举报