艾瑞克的 Hexo 空間

筆記-incron 簡介

incron 簡單介紹

incron 是一個Linux 上的小工具,可以用來監控特定目錄,當目錄內容發生變化時,可以執行自訂的script

可以監控的動作如下

incron可監控的動作

語法範例

incrontab -e (編輯)

語法 source_folder/mask(可以用多個不同動作,中間用 , 隔開)/要執行的script

/usr/share/nginx/html/hexoblog/source/_posts/ IN_MODIFY,IN_CREATE,IN_DELETE,IN_MOVE /scripts/run.sh

這行指令是說當 /usr/share/nginx/html/hexoblog/source/_posts/ 這個目錄產生變化(修改、新增、刪除、搬移)時,執行 /scripts/run.sh ,當然指令內容就看要怎麼應用。 在 /var/log/cron 裡面可以看到有沒有乖乖聽話在執行

Jul 12 04:28:17 3cx1 incrond[11814]: (root) CMD (/scripts/run.sh)
Jul 12 04:28:21 3cx1 incrond[11814]: (root) CMD (/scripts/run.sh)
Jul 12 04:28:21 3cx1 incrond[11814]: (root) CMD (/scripts/run.sh)

有點像是之前玩過的 lsyncd / inotify 的工具

目前是拿來作為自動偵測並發布Hexo Blog的「手段」,先透過win-sshfs之類的工具,mount 伺服器上的 Hexo Blog 的source/_posts目錄,然後在本地端的筆電上用Markdown editor編輯文章後,直接存在這個掛進來的目錄,然後透過 incron去自動執行hexo generate的指令,還滿方便的!

IN_ACCESS           File was accessed (read) (*)
IN_ATTRIB           Metadata changed (permissions, timestamps, extended attributes, etc.) (*)
IN_CLOSE_WRITE      File opened for writing was closed (*)
IN_CLOSE_NOWRITE    File not opened for writing was closed (*)    
IN_CREATE           File/directory created in watched directory (*)
IN_DELETE           File/directory deleted from watched directory (*)
IN_DELETE_SELF      Watched file/directory was itself deleted
IN_MODIFY           File was modified (*)
IN_MOVE_SELF        Watched file/directory was itself moved
IN_MOVED_FROM       File moved out of watched directory (*)
IN_MOVED_TO         File moved into watched directory (*)
IN_OPEN             File was opened (*)
avatar
雜念-網路中文 Net-chinese 的DNS 服務更新好慢啊!

  1. 1. incron 簡單介紹