0

I want to run a command each time a directory is updated (new/changed file within). I found this thread suggesting entr. I've made a script applying entr but it doesn't seem to work as intended.

#!/bin/bash
ls -d * /Users/me/test | entr echo hey

when I run the script it echos "hey" once, but if I add new files to test stdout just hangs without echoing another "hey".

Dudi Boy
  • 4,551
  • 1
  • 15
  • 30
Brian Barry
  • 439
  • 2
  • 17
  • 2
    Check the second part of the answer you've linked : for directories, add `-d` to `entr` and put it in a loop – Aaron Mar 23 '22 at 22:51
  • 1
    If you only want to monitor `/Users/me/test`, you just need `echo /Users/me/test | entr -d echo hey` – Barmar Mar 23 '22 at 22:53

1 Answers1

1

Suggesting to use systemd path units.

Here is a tutorial about monitoring a path unit.

And here is a more general explanation of systemd units.

Advantages of of systemd path units:

  1. Most flexible
  2. Decouples event management from action management from run-time control
  3. Strong central logging and auditing
  4. Standard location and information about systemd units
  5. Standard for event management and action management

Disadvantages of systemd path units:

  1. Complex
  2. Requires admin permissions
  3. Depends on systemd
Dudi Boy
  • 4,551
  • 1
  • 15
  • 30