写了一个脚本来传输文件,类似于这样:
[shell]
sendsystem(){
expect -c "
spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/system01.dbf oracle@$S_IP:$ORACLE_BASE/oradata/standby/
expect {
yes/no { send \"yes\r\"; exp_continue }
*assword* { send \"oracle\r\" }
};
expect 100%
expect eof ;
"
}
[/shell]

[shell]
sendsysaux(){
expect -c "
spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/sysaux01.dbf oracle@$S_IP:$ORACLE_BASE/oradata/standby/
expect {
yes/no { send \"yes\r\"; exp_continue }
*assword* { send \"oracle\r\" }
};
expect 100%
expect eof ;
"
}
[/shell]

[shell]
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 oracle@192.168.134.134:/oracle/oradata/standby/
oracle@192.168.134.134'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 oracle@192.168.134.134:/oracle/oradata/standby/
oracle@192.168.134.134'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
[/shell]
system01.dbf没传完就不传了
又试了几次发现偶尔其他文件也会传不完就不传了

最后发现是因为expect默认timeout为30S
手动添加set timeout -1设置超时时间为无穷大,问题解决
[shell]
sendsystem(){
expect -c "
set timeout -1
spawn scp $ORACLE_BASE/oradata/$ORACLE_SID/system01.dbf oracle@$S_IP:$ORACLE_BASE/oradata/standby/
expect {
yes/no { send \"yes\r\"; exp_continue }
*assword* { send \"oracle\r\" }
};
expect 100%
expect eof ;
"
}
[/shell]
---------------------
作者:Fan_-_
来源:CSDN
原文:https://blog.csdn.net/ashic/article/details/46914589
版权声明:本文为博主原创文章,转载请附上博文链接!

发表评论

邮箱地址不会被公开。 必填项已用*标注