Advertisement
xurxosanz

inotifywait example

Dec 15th, 2011
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.66 KB | None | 0 0
  1. #!/bin/bash
  2. function log {
  3.   echo "[`date  +%y/%m/%d-%H:%M:%S`] $1" | tee -a $LGMLOGFILE  
  4. }
  5.  
  6. log "Starting inotitywait infinite loop"
  7.  
  8. inotifywait --format "%f %e"  -me close_write,moved_to,moved_from,delete,delete_self  $FOLDERWATCHED | while read LINE
  9. do
  10.   log "processing $LINE..."
  11.  
  12.   set -- "$LINE"
  13.   IFS=" "; declare -a Array=($*)
  14.   FILE="${Array[0]}"
  15.   EVENT="${Array[1]}"
  16.  
  17.   FILENAME=${FILE%.*}
  18.   FILEEXT=${FILE##*.}
  19.   IFS=""
  20.  
  21.   # select by file extension
  22.   case $FILEEXT in
  23.  
  24.   txt)
  25.     # do something
  26.   ;;
  27.  
  28.   map)
  29.     # do another stuff
  30.   ;;
  31.   *)
  32.     log "nothing to do with $FILE"
  33.   ;;
  34.   esac
  35. done
  36. log "Script finisched"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement