Helen Neely
Helen Neely

Reputation: 4740

Using GREP and Inotifywait

I have this small script and I was wondering if someone could tell me where I'm going wrong. It is basically watching a folder, and if a file with .php.something-else is uploaded, it should be deleted.

How do I get grep the file name? Essentially, I want to check if FILE has an extention .php.something-else.

inotifywait -m -r --format '%w%f' -e create /samplefolder | while read FILE
do
      if grep '*.php.* ; then  <<-----HERE, I WANT THE FILE NAME
         /bin/rm $FILE
      fi     
done

Upvotes: 1

Views: 538

Answers (1)

P.P
P.P

Reputation: 121407

You don't need grep. Check for the file's existence and delete it:

if [ -f *.php.* ] ; then 
     /bin/rm $FILE
  fi     

You can use case to match it:

case $FILE in
*.php.*)
     /bin/rm $FILE
esac

Upvotes: 2

Related Questions