Security
官方網站
https://python-watchdog.readthedocs.io/en/stable/quickstart.html
環境準備
安裝 pip
https://www.delftstack.com/zh-tw/howto/linux/how-to-install-the-pip-package-manager-on-ubuntu/
下載watchdog
pip install -U watchdog
執行
python3 watchdog2.py
將會監控python執行檔案的區塊進行監控該區塊的所有跟sub dir進行監控異動
可以額外增加參數,就可以指定該目錄底下所有檔案才會監測
python3 watchdog2.py /home/xxx/subdir
以下是console呈現的結果:
xx@localhost:~/文件$ python3 watchdog2.py
2022-08-12 13:51:00 - Modified file: ./logseq/.git
2022-08-12 13:51:00 - Modified file: ./logseq/.git
2022-08-12 13:51:00 - Modified directory: ./logseq
2022-08-12 13:51:03 - Created file: ./新檔案
2022-08-12 13:51:03 - Modified directory: .
2022-08-12 13:51:03 - Modified directory: .
2022-08-12 13:51:23 - Deleted file: ./新檔案
2022-08-12 13:51:23 - Modified directory: .
本次日誌改用append模式,寫入file,加料的字串是準備塞入主機名稱
改寫增加監控的dir數量
Error
Error 1 python執行檔案與watchdog lib同名
https://stackoverflow.com/questions/63219913/no-module-named-watchdog-observers-watchdog-is-not-a-package
Error 2 Sample Code有錯誤
Error 2 ip抓到127.0.0.1
import socket
print(socket.gethostbyname(socket.gethostname()))
https://www.delftstack.com/zh-tw/howto/python/get-ip-address-python/
https://medium.com/analytics-vidhya/monitoring-your-file-system-using-watchdog-64f7ad3279f