linux 复制文件到另一个服务器脚本 scp expect
这里用到了expect 命令,需要先安装tcl 然后 安装expect
安装不再介绍可以参考下面链接:https://www.cnblogs.com/daojian/archive/2012/10/10/2718390.html
脚本代码:oracle备份
#!/bin/sh export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1 export ORACLE_SID=orcleas export ORACLE_TERM export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH export LD_LIBARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export LANG=C export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK expdp name/password directory=ORABACK schemas=xxxxx dumpfile=OKINGDEE"`date +%Y%m%d`".dmp logfile=OKINGDEE"`date +%Y%m%d`".log tar -czPf /home/oraback/OKINGDEE"`date +%Y%m%d`".tar.gz /home/oraback/OKINGDEE"`date +%Y%m%d`".dmp /home/oraback/OKINGDEE"`date +%Y%m%d`".log rm -rf /home/oraback/OKINGDEE"`date +%Y%m%d`".dmp /home/oraback/OKINGDEE"`date +%Y%m%d`".log find /home/oraback -type f -name "*.tar.gz" -mtime +30 -exec rm -rf {} \;
脚本代码:将oracle备份文件 复制到另一台服务器 实测可用【expect会让里面变量无法使用 下面这种方法是可行的】
#!/usr/local/bin/expect set proj_dir /home/oraback/OKINGDEE set remote_dir /home/backdata/out/ set password bicon@123set date2 [exec date "+%Y%m%d"] spawn scp $proj_dir$date2.tar.gz root@10.1.2.20:${remote_dir} set timeout 300 expect { "(yes/no)?" { send "yes\n" expect "*assword:" { send "$password\n"} } "*assword:" { send "$password\n" } } expect eof