views:

39

answers:

3

I want to automatically kick off a build whenever a file changes.

I've used autospec (RSpec) in Ruby and loved that.

How can this be done in bash?

+1  A: 

keywords are inotifywait & inotifywatch commands

zed_0xff
A: 

I did it with this :-

#!/bin/bash

ls -ltR > .monitor_compare1

not_changed () {
   echo "No changes yet..."
}

changed () {
    echo "Changed!"
    # perform build
}

while true; do

    ls -ltR > .monitor_compare1

    diff .monitor_compare1 .monitor_compare2 >> /dev/null && not_changed || changed

    cp .monitor_compare1 .monitor_compare2

    sleep 1

done

But I have also read the stat command might be better/quicker!

IanVaughan
A: 

Take a look at incron and inotify-tools.

Dennis Williamson