dotfiles/system/bin/watch.sh
Severin Kaderli 5c893b60aa Add watch.sh and update utils.sh
Signed-off-by: Severin Kaderli <severin.kaderli@gmail.com>
2018-12-19 22:54:34 +01:00

29 lines
No EOL
513 B
Bash
Executable file

#!/bin/bash
#
# SCRIPT NAME:
# watch.sh
#
# AUTHOR:
# Severin Kaderli <severin.kaderli@gmail.com>
#
# DESCRIPTION:
# This script watches a file for changes and if it changes it
# executes the given command.
#
# USAGE:
# ./watch.sh FILE COMMAND...
. utils.sh
# The file to watch
FILE="${1}"
# The rest of the arguments is the command
shift
COMMAND="${@}"
print_header "Watching ${FILE}"
while inotifywait -qq -e close_write "${FILE}";
do
print_log "File has changed, executing command"
$($COMMAND)
done