首页 > 代码库 > Shell结合Expect实现自动输入密码

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 eof10 EOF11 12 time=`/bin/date "+%Y%m%d%H%M%S"`13 cd dir1 && tar czf /data/www/dir2_$time.tar.gz dir214 cd .. && rm -rf dir115 if [ $? -eq 0 ]16 then17     echo "Download here: http://10.13.38.22/dir2_"$time".tar.gz"18 else19     echo "Download Error!"20 fi

 

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