Comment lancer une commande quand un fichier est déposé dans un répertoire ?
#!/bin/sh
# CONFIGURATION
DIR="/var/www/handibouge.fr/admin/ftp/1/"
EVENTS="close_write"
FIFO="/tmp/inotify2.fifo"
# FUNCTIONS
on_exit() {
kill $INOTIFY_PID
rm $FIFO
exit
}
on_event() {
local date=$1
local time=$2
local file=$3
echo "$date $time Fichier créé: $file"
}
# MAIN
if [ ! -e "$FIFO" ]
then
mkfifo "$FIFO"
fi
inotifywait -m -e "$EVENTS" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' "$DIR" > "$FIFO" &
INOTIFY_PID=$!
trap "on_exit" 2 3 15
while read date time file
do
on_event $date $time $file &
done < "$FIFO"
on_exit