写了一个脚本来传输文件,类似于这样:
sendsystem(){
expect -c "
spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/system01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/
expect {
yes/no { send \"yes\r\"; exp_continue }
*assword* { send \"oracle\r\" }
};
expect 100%
expect eof ;
"
}
sendsysaux(){
expect -c "
spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/sysaux01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/
expect {
yes/no { send \"yes\r\"; exp_continue }
*assword* { send \"oracle\r\" }
};
expect 100%
expect eof ;
"
}
结果:
spawn scp /home/oracle/std_control01.ctl oracle@192.168.134.134:/oracle/oradata/standby/std_control01.ctl
oracle@192.168.134.134‘s password:
std_control01.ctl 100% 9520KB 9.3MB/s 00:00
spawn scp /oracle/oradata/orcl/system01.dbf [email protected]:/oracle/oradata/standby/
[email protected]‘s password:
system01.dbf 92% 646MB 33.9MB/s 00:01 ETA
spawn scp /oracle/oradata/orcl/sysaux01.dbf oracle@192.168.134.134:/oracle/oradata/standby/
oracle@192.168.134.134‘s password:
sysaux01.dbf 100% 600MB 31.6MB/s 00:19
spawn scp /oracle/oradata/orcl/temp01.dbf [email protected]:/oracle/oradata/standby/
[email protected]‘s password:
temp01.dbf 100% 200MB 66.7MB/s 00:03
spawn scp /oracle/oradata/orcl/undotbs01.dbf oracle@192.168.134.134:/oracle/oradata/standby/
oracle@192.168.134.134‘s password:
undotbs01.dbf 100% 200MB 40.0MB/s 00:05
system01.dbf没传完就不传了
又试了几次发现偶尔其他文件也会传不完就不传了
最后发现是因为expect默认timeout为30S
手动添加set timeout -1设置超时时间为无穷大,问题解决
sendsystem(){
expect -c "
set timeout -1
spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/system01.dbf [email protected]$S_IP:$ORACLE_BASE/oradata/standby/
expect {
yes/no { send \"yes\r\"; exp_continue }
*assword* { send \"oracle\r\" }
};
expect 100%
expect eof ;
"
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-18 19:48:03