本文共 1641 字,大约阅读时间需要 5 分钟。
date1=`date --date='1 day ago' +%Y%m%d`
/justin/./sqluldr2_linux64_10204.bin justin/**** sql=/justin/sftp.sql field=## charset="ZHS16GBK" file=/justin/product"$date1".csv
scp /justin/product"$date1".csv rm /justin/product"$date1".csv在中转server上部署以下脚本
[deploy@justin ~]$ more sftp.shdate1=`date --date='1 day ago' +%Y%m%d`sftp -oPort=3222 justin@*.*.*.* << END
cd /uploadlcd /home/deploymput product$date1.csvENDrm /home/deploy/product$date1.csv
同样为了避免sftp输入密码的人机交互,使用expect命令先通过root用户yum install expect安装expect,然后输入autoexpect sftp.sh,此时会产生一个名为script.exp的文件,每次只需调用./script.exp即可自动完成sftp到remote server并上传文件的操作似乎只能通过./script.exp的方式调用该文件,设置crontab时候比较麻烦,可以新建一个文件[deploy@justin ~]$ more sftpexec.shcd /home/deploy./script.expCrontab设置则如下[deploy@justin ~]$ crontab -l0 2 * * * sh /home/deploy/sftpexec.sh > /home/deploy/sftpexec.log 2>&1而生成的script.exp内容如下
[deploy@justin ~]$ more script.exp #!/usr/bin/expect -f set force_conservative 0 ;# set to 1 to force conservative mode even if ;# script. wasn't run conservatively originallyif {$force_conservative} { set send_slow {1 .1} proc send {ignore arg} { sleep .1 exp_send -s -- $arg }} set timeout -1spawn ./sftp.shmatch_max 100000expect -exact "Connecting to *.*.*.*...\r password: "send -- "password\r"expect eof来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15480802/viewspace-708026/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15480802/viewspace-708026/