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下
