Bash script, watch folder, execute command

后端 未结 12 1322
小鲜肉
小鲜肉 2020-12-04 08:57

I am trying to create a bash script with 2 parameters:

  • a directory
  • a command.

I want to watch the

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 09:19

    To continuously recursively monitor folder (md5) and execute a command on change:

    daemon() {
        chsum1=""
    
        while [[ true ]]
        do
            chsum2=`find src/ -type f -exec md5 {} \;`
            if [[ $chsum1 != $chsum2 ]] ; then           
                compile
                chsum1=$chsum2
            fi
            sleep 2
        done
    }
    

    Works on my OS X as I do not have digest.

    On Linux, you can use md5sum as a replacement for the md5 command.

提交回复
热议问题