From 5c893b60aa02ad236f3d151a83103af39d41bd2a Mon Sep 17 00:00:00 2001 From: Severin Kaderli Date: Wed, 19 Dec 2018 22:54:34 +0100 Subject: [PATCH] Add watch.sh and update utils.sh Signed-off-by: Severin Kaderli --- system/bin/utils.sh | 8 ++++++++ system/bin/watch.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 system/bin/watch.sh diff --git a/system/bin/utils.sh b/system/bin/utils.sh index f648f4c..6fddb8a 100755 --- a/system/bin/utils.sh +++ b/system/bin/utils.sh @@ -35,10 +35,18 @@ YELLOW='\033[33m' # USAGE: print_header TITLE function print_header() { echo -e "\n${GREEN}########################################" + echo -e "#" echo -e "# ${1}" + echo -e "#" echo -e "########################################${RESET}" } +# Function to print a info message with the current time +# USAGE: print_info MESSAGE +function print_log() { + echo -e "${YELLOW}[$(date "+%H:%M:%S")] ${1}${RESET}" +} + # Creates the given directory in the home directory # USAGE: create_directory DIRECTORY function create_directory() { diff --git a/system/bin/watch.sh b/system/bin/watch.sh new file mode 100755 index 0000000..4bac65d --- /dev/null +++ b/system/bin/watch.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# SCRIPT NAME: +# watch.sh +# +# AUTHOR: +# Severin Kaderli +# +# 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 \ No newline at end of file