首先,我們來做一個(gè)shell腳本

[root@localhost rsyncd]# vim rsyncd.sh

#!/bin/bash

rsync -arvz –progress /data rsync@192.168.0.252::log –password-file=/rsyncd/rsyncd.pass

命令:crontab -e來編輯加入計(jì)劃任務(wù)

[root@localhost ~]# crontab -e
# DT:Execute rsync-sh script every Sunday at 00: 00(注釋說明)

0 0 * * 7 sh /root/rsyncd/rsyncd.sh

使用crontab -l查看加入的計(jì)劃任務(wù)

[root@localhost ~]# crontab -l
0 0 * * 7 sh /root/rsyncd/rsyncd.sh

注意:

1. 當(dāng)程式在你所指定的時(shí)間執(zhí)行后,系統(tǒng)會(huì)寄一封信給你,顯示該程式執(zhí)行的內(nèi)容,若是你不希望收到這樣的信,請(qǐng)?jiān)诿恳恍锌找桓裰蠹由?> /dev/null 2>&1 即可。

2. %在crontab中被認(rèn)為是newline,要用\來escape才行。比如crontab執(zhí)行行中,如果有”date +%Y%m%d”,必須替換為:”date +\%Y\%m\%d”

遇到的問題和解決方法:

在Windows上面編輯了sh腳本上傳到Linux上面,執(zhí)行報(bào)錯(cuò):

bad interpreter:No such file or directory

vim rsyncd.sh用命令:set ff?查看是doc還是unix格式,如果是dos格式,用命令:set ff=unix轉(zhuǎn)化為unix格式

來源:https://www.cnblogs.com/Sungeek/p/9561833.html

贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-62778877-8306;郵箱:fanjiao@west.cn。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明出處:西部數(shù)碼知識(shí)庫 » centos7下rsync+crontab定期同步備份

登錄

找回密碼

注冊(cè)