0

I am trying to use inotifywait within a bash script to monitor a directory for a file with a certain tag in it (*SDS.csv).

I also only want to execute once (once when the file is written to the directory data ).

example:

#! /bin/bash
inotifywait -m -e /home/adam/data | while read LINE
do
  if [[ $LINE == *SDS.csv ]]; then
     ./another_script.sh
  fi
done
nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52
SciGuyMcQ
  • 993
  • 6
  • 21

1 Answers1

0

While this may not be the ideal solution, it may do the trick:

#! /bin/bash
while true
do
    FNAME="$(inotifywait -e close_write /home/adam/data | awk '{ print $NF }')"

    if [ -f "/home/adam/data/$FNAME" ]
    then
      if grep -q 'SDS.csv' "/home/adam/data/$FNAME"
      then
         ./another_script.sh
      fi
    done
done
ash
  • 4,867
  • 1
  • 23
  • 33