How do I watch a file for changes?

前端 未结 25 2782
孤街浪徒
孤街浪徒 2020-11-21 07:13

I have a log file being written by another process which I want to watch for changes. Each time a change occurs I\'d like to read the new data in to do some processing on it

25条回答
  •  天涯浪人
    2020-11-21 07:56

    Simplest solution for me is using watchdog's tool watchmedo

    From https://pypi.python.org/pypi/watchdog I now have a process that looks up the sql files in a directory and executes them if necessary.

    watchmedo shell-command \
    --patterns="*.sql" \
    --recursive \
    --command='~/Desktop/load_files_into_mysql_database.sh' \
    .
    

提交回复
热议问题