4
4

More than 5 years have passed since last update.

フォルダを監視してサイズ変更があれば コマンドを実行する君作った

Last updated at Posted at 2013-07-29

使い方

$ ./modified_then_exec.sh memo.rst "make html"
$ ./modified_then_exec.sh ./doc/ "make singlehtml"
$ ./modified_then_exec.sh index.php "php -l index.php"
modified_then_exec.sh
#!/bin/sh

SLEEP=1

execute() {
    echo "[$(date +"%Y/%m/%d %H:%M:%S")] $COMMAND ________________________________"
    $COMMAND
    TIME_MODIFY=$CHECK_TIME
}

validate() {
    if [ "$COMMAND" = "" ]; then
        echo "[usage] $0 filename 'command' need."
        exit 0
    elif [ ! -e "$FILENAME" ]; then
        echo "[quit] $FILENAME no such file or directory."
        exit 0
    fi
}

FILENAME=$1
COMMAND=$2
validate
TIME_MODIFY=$(du -b $FILENAME)

while true;do
    CHECK_TIME=$(du -b $FILENAME)
    if [ "$TIME_MODIFY" != "$CHECK_TIME" ]; then
        execute
    fi
    sleep $SLEEP
done

download

4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4