blueice 发表于 2018-8-19 14:21:34

shell中调用expect小例子

#!/bin/bash  
code_path='/root/'
  
mysql_file='recharge*.gz'
  
#mysql_file1='refund*.gz'
  
hosts=`cat all.hosts`
  
logname='/tmp/expect.log'
  
rm -rf $logname
  
for i in $hosts;
  
do
  
#   echo $ipadd
  
ipadd=`echo $i|awk -F, '{print $1}'`
  
password=`echo $i|awk -F, '{print $2}'`
  
cine_name=`echo $i|awk -F, '{print $3}'`
  
expect -c"
  
set timeout 600
  
spawn /usr/bin/scp -l 1024 $ipadd:${code_path}${mysql_file} /root/wzp/all/
  
log_file $logname
  
expect {
  
\"*yes*\" {send \"yes\r\"; exp_continue}
  
\"*password*\" {send \"$password\r\";}
  
}
  
expect eof;"
  
done


页: [1]
查看完整版本: shell中调用expect小例子