
我用來unison
將資料同步到伺服器,最近我為此創建了一個 cronjob。 cronjob 在啟動時運行並將輸出保存到日誌檔案中。 (下面有更多資訊)。
我遇到的問題是一致有相當多的輸出,我只想將摘要儲存到日誌檔案中。有沒有辦法做到這一點?我還沒有找到一種方法來使一致性不那麼冗長,所以我想也許可以以某種方式過濾輸出 - 我只是不知道如何過濾。
謝謝!
附加資訊:
現在,日誌檔案最終看起來像這樣:
Contacting server...
Connected [//theserver//share/HDA_DATA/elrudi -> //thelaptop//home/elrudi]
Looking for changes
\ syncAll/Code/Aptana/T...avascript library code assist.txt
\ syncAll/Code/develope...nk/20070607 contacten (INDEX).xls
\ syncAll/Code/sourcefi...okexport/photos/10152112061815397
| syncAll/Code/Python/d...rawable-hdpi/ic_action_search.png
(... many many lines ...)
| syncAll/Work/2008_10 ...profile/StandardLastprofil_H0.xls
| syncAll/Work/2008_10 ...n/Load Profiles/Lastprofil_H0.xls
Waiting for changes from server
Reconciling changes
changed ----> syncAll/scriptfile1.sh
Propagating updates
UNISON 2.40.102 started propagating changes at 12:07:31.55 on 07 Oct 2015
[BGN] Updating file syncAll/scriptfile1.sh from /home/elrudi to //theserver//share/HDA_DATA/elrudi
100% 00:00 ETA
[END] Updating file syncAll/scriptfile1.sh
100% 00:00 ETA
UNISON 2.40.102 finished propagating changes at 12:07:31.61 on 07 Oct 2015
100% 00:00 ETA
Saving synchronizer state
Synchronization complete at 12:07:36 (1 item transferred, 0 skipped, 0 failed)
我想放棄以|
、/
、-
或開頭的行\
(指示進程尚未完成的旋轉條)。
更多附加資訊:
crontab -e
顯示
@reboot /home/elrudi/sync.sh -batch 60 >> /home/elrudi/.cronjobs.log 2>&1
該sync.sh
腳本檢查伺服器是否可以在本地或遠端訪問,並運行適當的unison
命令。添加該-batch
參數是為了在unison
無需用戶輸入的情況下運行,並且60
是等待時間(以確保unison
在連接可用之前不會運行)。
答案1
當您呼叫unison
腳本時sync.sh
,請按以下方式呼叫:
unison ... 2>&1 | grep -vE '^[\|/-]|^$'
這將刪除 ( -v
) 與正規表示式相符的所有行:以這些字元之一開頭的所有行:\|/-
,或完成空白行 ( ^$
)。
編輯:如果您希望過濾 cronjob,請使用:
@reboot /path/to/sync.sh -batch 60 2>&1 | grep -vE '^[\|/-]|^$' >> /path/to/logfile