linux之间远程拷贝文件


linux之间远程拷贝文件,新手的土方法,写着玩留作备份,有问题请指正:

copyforder.sh

 1 #!/bin/sh
 2 BASEHOME=/home/han/base
 3 data=`date +%Y%m%d`
 4 
 5 #过滤我想要的格式 0000160816 
 6 
 7 #将data日期截串 20160816 -> 160816
 8 
 9 fdr=*0000${data:2}*
10 
11 #ssh 远程登录获取目录列表>并将内容写入日志
12 ssh -l root 192.168.11.111 "ls -d /home/han/send/$fdr" > /home/han/log/copy_${data:2}.log
13 
14 #将每一行传到exscp.sh中去执行
15 while read line || [[ -n ${line} ]];
16 do
17 str=$line
18 substr=${str##*/}
19 /home/han/base/./exscp.sh $substr
20 done < /home/han/log/copy_${data:2}.log #当天日志
21 #功能 过滤需要接收的文件

 

excopy.sh

1 #!/software/expect5.45/expect
2 set timeout 60s
3 spawn /home/han/base/copyforder.sh
4 expect "assword" { send "666666\r"}
5 interact
6 #功能 ssh输入密码

 

exscp.sh

#!/software/expect5.45/expect
set substr [lindex $argv 0] 
set timeout 120s
spawn scp -r root@192.168.11.111:/home/han/send/$substr/ /home/han/base/
expect "assword" { send "666666\r"}
expect eof
#功能 scp自动输入密码

将远程send下的某个目录拷贝到本地base下


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM