TS-421 file change information mail
Posted: Fri Nov 28, 2014 8:51 pm
Is there a way to send mail if a file added, deleted or changed in a folder to user which have access that folder.
As long as your Notifications feature is working on your NAS, you can use the following script to watch a users $HOME directory for changes. Please feel free to modify it to your requirements.oahiskali wrote:Is there a way to send mail if a file added, deleted or changed in a folder to user which have access that folder.
Code: Select all
#!/bin/sh
#
# watchdir.sh [username]
#
# This script will watch the $HOME for [username] and send an e-mail if any files change within it.
# This script requires that the "Home Folders" feature is enabled. See: http://docs.qnap.com/nas/4.1/Home/en/users.htm
#
if [ "$1x" = "x" ]; then
echo "Usage: $0 [username]"
echo " "
echo "This script will watch the \$HOME for [username]"
else
user=$1
dir=$(grep $user /etc/config/passwd | cut -d: -f6)
fi
echo "done"
[ ! -d $dir ] && echo "$dir does not seem to exist"
SendTo="me@somewhere.com"
SendFrom="watchdir.sh@XXXXXXXX.myqnapcloud.com"
Subject="\$HOME ($dir) directory for $user changed."
#
#
rm -f /tmp/watchdir.email
touch /tmp/watchdir.email
echo "From: ${SendFrom}" >>/tmp/watchdir.email
echo "To: ${SendTo}" >>/tmp/watchdir.email
echo "Subject: ${Subject}" >>/tmp/watchdir.email
echo " " >>/tmp/watchdir.email
while true #run indefinitely
do
inotifywait -r -e modify,attrib,close_write,move,create,delete $dir >>/tmp/watchdir.email \
&& cat /tmp/watchdir.email | sendmail -t
done
rm -f /tmp/watchdir.email
#done
Code: Select all
chmod +x /share/homes/admin/bin/watchdir.sh
Code: Select all
/share/homes/admin/bin/watchdir.sh admin &
Scripts work the same way under Windows, OS X, and Linux. I am happy to write scripts for anyone, but I'm not into Video production. I have provided a script that works, and that I have tested to ensure that it works. You have not educated what Operating System you are using on your PC, so I wouldn't know where to start when it comes to implementing this on your NAS.oahiskali wrote:Thanks Patrick,
But I dont know how to use a script.I would be thankful if you can record a video for it.
Regards
Onur