之前写的shell脚本 感觉比较麻烦
代码如下
#! /bin/bash
#pass后面为目的ip地址的密码,此处密码为root
PASS=dfjaifda@!jf12343
#PASS1=dfjaifda@!jf12343
#那么后面为目的ip地址的用户名,此处用户名为root
USER=root
IP=47.96.111.2
#IP1=119.28.156.234
#下面调用scp,-r表示递归传输
address=/home/vega/yum-3.4.3.tar.gz #为源地址
#47.96.111.2为目的ip
Destinationaddress=/root#为目的地址
path=yum
yum=yum-3.4.3.tar.gz
expect -c "
spawn scp -r $address $name @$ip:$Destinationaddres
expect {
\"*assword\" {set timeout 300; send \"$password\r\"; exp_continue;}
\"yes/no\" {send \"yes\r\";}
}
expect eof
## 传输 100% 完成后,登录并解压
expect -c "
spawn ssh -p 22 $USER@$IP
expect {
\"(yes/no)\" {send \"yes\r\"; exp_continue}
\"password:\