Skip to content

Instantly share code, notes, and snippets.

@6LYTH3
Last active August 29, 2015 14:04
Show Gist options
  • Save 6LYTH3/eb21b5ce7a5be7c2b59a to your computer and use it in GitHub Desktop.
Save 6LYTH3/eb21b5ce7a5be7c2b59a to your computer and use it in GitHub Desktop.
Monitor the newest file.
#!/bin/bash
SCRIPT=/home/vagrant/repository/bash/iNotify.sh
HB=`ps aux|grep -i inotify.sh|grep -v grep|grep -v Z|wc -l`
if [ $HB -le 0 ]; then
bash $SCRIPT &
fi
#!/bin/bash
SOURCE=/home/vagrant/lab1/source
DESTINATION=/home/vagrant/lab1/destination
OLDDIFF=`diff -qr $SOURCE $DESTINATION | grep Files | awk '{print $2 }'`
NEWDIFF=`diff -qr $SOURCE $DESTINATION |grep Only|awk '{print $3$4}'|sed 's/:/\//'`
for FILE in $NEWDIFF
do
if [ `file $FILE | awk '{print $2}'` != "directory" ]; then
echo $FILE
fi
done
#!/bin/bash
SOURCE=/home/vagrant/lab1/source
DESTINATION=/home/vagrant/lab1/destination
SOURCE_L=${#SOURCE}
DESTINATION_L=${#DESTINATION}
inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
-e CLOSE_WRITE $SOURCE | while read date time dir file; do
REALFILE=${dir}${file}
### filter system process and vi editor ###
if ! [[ $file =~ ^[0-9] || $file =~ [swp] ]]; then
echo -e "At ${time} on ${date}, file ${REALFILE} detected "
FILE=${REALFILE:SOURCE_L + 1:DESTINATION_L}
cd $SOURCE
cp --parent $FILE $DESTINATION
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment