linux 定時遠端檔案傳輸
阿新 • • 發佈:2019-08-24
參考 : https://blog.csdn.net/u012310859/article/details/79364881
遠端需要傳輸的檔案是每天自動生成的資料庫備份
如果沒有安裝lftp
安裝
yum install lftp -y
建立sh 檔案
#!/bin/bash #SFTP配置資訊 #IP IP=111.111.111.111 #埠 PORT=22 #使用者名稱 USER=root #密碼 PASSWORD=1111111111 #待上傳檔案根目錄 CLIENTDIR=/mnt/mysql-backup #SFTP目錄 SEVERDIR=/usr/mysql-backup #待上傳檔名 d2=`date +%Y%m%d` FILE="zita_wms-"$d2"_013001.dump" lftp -u ${USER},${PASSWORD} sftp://${IP}:${PORT} <<EOF cd ${SEVERDIR}/ lcd ${CLIENTDIR} put ${FILE} by EOF
授權檔案操作
chmod 777 upload_zita_wms.sh
如果再windows 裡面編輯的檔案,放到linux 裡面,需要更改為unix的檔案格式
如:
vi upload_zita_wms.sh
:set ff=unix
:wq!
如果再linux 裡面建立檔案
touch upload_zita_wms.sh
按 i 編輯內容
:wq!
退出
編輯sh 檔案前 可以測試是否可用
lftp -u root,11111111 sftp://111.111.111.111:22 <<EOF cd /usr/mysql-backup lcd /usr/sh/ put a.xlsx by EOF
編輯完成後可以直接呼叫
/usr/sh/upload_zita_wms.sh
放到contab 裡面
root身份登入到命令列
輸入crontab -e
按下a鍵進入到編輯模式
輸入 0 */1 * * * /usr/sh/start-upload_zita_wms.sh
同時按下ctrl+c退出編輯模式
按下shift+: 輸入wq 退出 crontab