Over a million developers have joined DZone.

Simple Files Watch Associated To Commands

·
The is the scenario: you want to run a command wherever a file (or files) is modified. 

This is the most basic approach (you will need inotify):


#!/bin/bash
# Usage: onchange.sh "COMMAND" FILE1 ... [FILEN]
set -e
RUNFIRSTLOOP=1

COMMAND=$1
shift
test "$RUNFIRSTLOOP" && bash -c "$COMMAND" || { echo "retcode: $?"; }

while inotifywait "$@"; do
  bash -c "$COMMAND" || { echo "retcode: $?"; }
done
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}