Email notification about new file upload (Shared Folder)?

Discuss with the community any ideas you'd love to see in future DiskStations and DSM updates! We do our best to monitor and forward all of them, but we recommend to also use this form as our team will systematically see your suggestion:
https://www.synology.com/en-global/form ... y/feedback
Forum rules
We do our best to monitor and forward your ideas to our team, but due to the large amount, we may not see every single one and recommend to also use this form as our team will systematically see your suggestion:
https://www.synology.com/en-global/form ... y/feedback
maravac
Rookie
Rookie
Posts: 34
Joined: Tue Dec 20, 2011 1:28 pm

Email notification about new file upload (Shared Folder)?

Postby maravac » Wed Apr 24, 2013 10:12 am

Hi there, please, is there any option to get from my Synology (DS212+) the email notification to my email address whenever anyone uploads new file (files) or changes the existing file in predefined shared folder, which will be dedicated for such a kind ofcoolaboration between me and rest of the users?

Thank you.

Marcus
totalcarnage
Trainee
Trainee
Posts: 14
Joined: Wed Jul 17, 2013 8:51 am

Re: Email notification about new file upload (Shared Folder)

Postby totalcarnage » Wed Jul 17, 2013 8:57 am

i'd also be interested on how to manage this notification mail from the system, if someone uploads, changes, deletes or modiefies folders/files in a predefined folder (ACL).

would be great if not only the admin gets this notifying mail but also some users with rights to access and modify that folder.
mb277
Trainee
Trainee
Posts: 11
Joined: Sun Nov 02, 2014 8:48 pm

Re: Email notification about new file upload (Shared Folder)

Postby mb277 » Sun Nov 02, 2014 8:49 pm

+1 Please add a feature to get a notification as soon as anybody has uploaded a file to photo station.

Kind regards
mb277
alinnert
I'm New!
I'm New!
Posts: 1
Joined: Mon Feb 09, 2015 8:24 pm

Re: Email notification about new file upload (Shared Folder)

Postby alinnert » Mon Feb 09, 2015 8:27 pm

I also need this feature since I'm planning to use my DiskStation for collaborating with others.
ifeatu
I'm New!
I'm New!
Posts: 9
Joined: Fri Dec 21, 2012 5:31 pm

Re: Email notification about new file upload (Shared Folder)

Postby ifeatu » Sun Mar 01, 2015 4:19 am

+1 for this feature. Much needed.
babymilo
I'm New!
I'm New!
Posts: 2
Joined: Sun Aug 02, 2015 6:06 pm

Re: Email notification about new file upload (Shared Folder)

Postby babymilo » Sun Aug 02, 2015 6:16 pm

Much needed filter for NEW file. Many ways to search for modified file filters but no NEW FILES. I also have homes shared folder that I need to search for NEW FILES. Any log or notifications would also be a improvement for NEW FILES.
sal623
I'm New!
I'm New!
Posts: 1
Joined: Sat Mar 10, 2012 9:52 pm

Re: Email notification about new file upload (Shared Folder)

Postby sal623 » Wed Aug 26, 2015 1:47 am

Anyone find a way?
mzn
Trainee
Trainee
Posts: 10
Joined: Mon Aug 01, 2016 6:46 pm

Re: Email notification about new file upload (Shared Folder)?

Postby mzn » Fri Jan 13, 2017 1:46 am

Given that there are a lot more talented and experienced people out there doing this, I don't understand why something like this hasn't been posted previously, but if you want to check a specific folder for any new files that have been uploaded and receive an email that new files have been added, I believe the best way to do this is via Scheduled Task (Control Panel --> Task Scheduler-->Create-->Scheduled Task-->User Defined Script).
Schedule to run daily, and select Frequency. I chose every 5 min. Also, select First Run Time = 00 and last run time=23:55 so that it checks the folder 24 hours a day, although you can modify it so that it only checks it during daytime hours.

Then, under Task Settings, enter the following Bash script:

cd '/volume1/whatever folder you want to monitor'
ls > current_dir
current_dir_len=$(wc -l < current_dir)
prior_dir_len=$(wc -l < prior_dir)
num_new_files=$((current_dir_len - prior_dir_len))
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
/usr/bin/php -r "mail('youremail@gmail.com, yourbossesemail@gmail.com','An additional $num_new_files new files(s) have been uploaded to your monitored folder','Some message in the body of the email.');"
fi
cp current_dir prior_dir

What the script does is only email you if there are MORE files in the monitored folder within the past 5 minutes, AND the files have different filenames. If you also want to be notified when a file has been deleted from the folder, then just remove '&& [ "$num_new_files" -gt 0 ]' in the if statement above. This will then trigger an email if any filenames have been changed, newly added, or newly deleted.
You can certainly make the above script "prettier", but it works, and can also work for monitoring of new photos added to a specific album.
karlzre
I'm New!
I'm New!
Posts: 1
Joined: Tue Jan 24, 2017 9:29 am

Re: Email notification about new file upload (Shared Folder)?

Postby karlzre » Tue Jan 24, 2017 9:33 am

Hi,

That script works well.

Any idea if it's possible to get the file name and add it in the e-mail message ?
djcjrich
I'm New!
I'm New!
Posts: 1
Joined: Tue Jan 24, 2017 6:49 pm

Re: Email notification about new file upload (Shared Folder)?

Postby djcjrich » Tue Jan 24, 2017 6:55 pm

Great Help. The script works perfectly. I would like to know if I can have the name of the user that uploaded/changed the file show up in the email notification. Also, can I have one script monitoring multiple folders notifying one email address similarly to having multiple people emailed when one folder is changed?
mzn
Trainee
Trainee
Posts: 10
Joined: Mon Aug 01, 2016 6:46 pm

Re: Email notification about new file upload (Shared Folder)?

Postby mzn » Tue Jan 24, 2017 11:33 pm

Hi,
As I had mentioned, unfortunately I'm new to this and I haven't had time to test it. However, there are lots of great tutorials on bash scripting online.

I believe the following modification sends the "new file list" to the user in the body of the email:

cd '/volume1/whatever folder you want to monitor'
ls > current_dir
current_dir_len=$(wc -l < current_dir)
prior_dir_len=$(wc -l < prior_dir)
num_new_files=$((current_dir_len - prior_dir_len))
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
new_file_list=$(diff -rn current_dir prior_dir)
/usr/bin/php -r "mail('youremail@gmail.com, yourbossesemail@gmail.com','An additional $num_new_files new files(s) have been uploaded to your monitored folder','These are the new files: $new_file_list.');"
fi
cp current_dir prior_dir

With regards to multiple folders, the easiest but least elegant method of tracking more than one folder is to repeat the script by copying a second copy of the entire script to the bottom of the original. Then just change the first line to: cd '/volume/second folder'.
Finally, to get the user who uploaded the new file, I believe that instead of the second line reading: ls > current dir, maybe try ls -l > current_dir. This would show the the file owner and therefore the user who uploaded the file.

Sorry I couldn't be of more precise help. I know the above requests are more than doable by someone who is better at BASH/UNIX scripting or someone who has a bit more time.
cwilkins3
I'm New!
I'm New!
Posts: 1
Joined: Fri Feb 10, 2017 5:36 pm

Re: Email notification about new file upload (Shared Folder)?

Postby cwilkins3 » Fri Feb 10, 2017 5:47 pm

This is what I get when I add a file. I tried adding the from command to the script. Any ideas on how to fix this using outlook or gmail does not work.
Dear user,

Task Scheduler has completed a scheduled task.

Task: contract added
Start time: Fri, 10 Feb 2017 10:34:02 GMT Stop time: Fri, 10 Feb 2017 10:34:04 GMT Current status: 0 Standard output/error:
ssmtp: 501 5.5.4 Invalid Email address


Sincerely,
Synology DiskStation

Here is my script with the from added in

cd '/volume1/homes/Apps/WP E-Signature - Sync (1)'
ls > current_dir
current_dir_len=$(wc -l < current_dir)
prior_dir_len=$(wc -l < prior_dir)
num_new_files=$((current_dir_len - prior_dir_len))
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
/usr/bin/php -r "mail('cwilkins0129@gmail.com, chad@legendsroofing.com','An additional $num_new_files new files(s) have been uploaded to your monitored folder','Some message in the body of the email.','-fchad@legendsroofing.com');"
fi
cp current_dir prior_dir

Thanks in advance. I'm new to this part.




mzn wrote:Given that there are a lot more talented and experienced people out there doing this, I don't understand why something like this hasn't been posted previously, but if you want to check a specific folder for any new files that have been uploaded and receive an email that new files have been added, I believe the best way to do this is via Scheduled Task (Control Panel --> Task Scheduler-->Create-->Scheduled Task-->User Defined Script).
Schedule to run daily, and select Frequency. I chose every 5 min. Also, select First Run Time = 00 and last run time=23:55 so that it checks the folder 24 hours a day, although you can modify it so that it only checks it during daytime hours.

Then, under Task Settings, enter the following Bash script:

cd '/volume1/whatever folder you want to monitor'
ls > current_dir
current_dir_len=$(wc -l < current_dir)
prior_dir_len=$(wc -l < prior_dir)
num_new_files=$((current_dir_len - prior_dir_len))
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
/usr/bin/php -r "mail('youremail@gmail.com, yourbossesemail@gmail.com','An additional $num_new_files new files(s) have been uploaded to your monitored folder','Some message in the body of the email.');"
fi
cp current_dir prior_dir

What the script does is only email you if there are MORE files in the monitored folder within the past 5 minutes, AND the files have different filenames. If you also want to be notified when a file has been deleted from the folder, then just remove '&& [ "$num_new_files" -gt 0 ]' in the if statement above. This will then trigger an email if any filenames have been changed, newly added, or newly deleted.
You can certainly make the above script "prettier", but it works, and can also work for monitoring of new photos added to a specific album.
mzn
Trainee
Trainee
Posts: 10
Joined: Mon Aug 01, 2016 6:46 pm

Re: Email notification about new file upload (Shared Folder)?

Postby mzn » Wed Feb 15, 2017 11:59 pm

So I think I've figured out how to include a list of the new files in the body of the email. Its still not an attachment but at least you'll know what files or images are new.

Please replace:
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
/usr/bin/php -r "mail('youremail@gmail.com, yourbossesemail@gmail.com','An additional $num_new_files new files(s) have been uploaded to your monitored folder','Some message in the body of the email.');"
fi

With:
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
sort current_dir >current.txt
sort prior_dir >prior.txt
comm -3 current.txt prior.txt >diff.txt
echo -e "From: \nSubject: Additional $num_new_files new photo(s) uploaded to photo frame\n\nNew files or pictures uploaded the folder being monitored." "$(<diff.txt)" | /usr/bin/ssmtp youremail@gmail.com, yourbossesemail@gmail.com
rm current.txt
rm prior.txt
rm diff.txt
fi


Please note that "current.txt" is a sorted version of the file "current_dir", which in turn is a list of the current files in the directory. Same with "prior.txt". Then "diff.txt" is a file listing anything different between "current.txt" and "prior.txt". The .txt files are temporary, and get deleted as soon as the email is sent out. I'm sure there's a more elegant way to do this, but it should work.
Jeff146
Trainee
Trainee
Posts: 17
Joined: Sun May 25, 2014 7:00 pm

Re: Email notification about new file upload (Shared Folder)?

Postby Jeff146 » Wed Jun 07, 2017 9:27 pm

I tried this and it doesn't send the email. Any insight? As there's no error message or anything.



mzn wrote:So I think I've figured out how to include a list of the new files in the body of the email. Its still not an attachment but at least you'll know what files or images are new.

Please replace:
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
/usr/bin/php -r "mail('youremail@gmail.com, yourbossesemail@gmail.com','An additional $num_new_files new files(s) have been uploaded to your monitored folder','Some message in the body of the email.');"
fi

With:
if ! (diff current_dir prior_dir> /dev/null) && [ "$num_new_files" -gt 0 ]
then
sort current_dir >current.txt
sort prior_dir >prior.txt
comm -3 current.txt prior.txt >diff.txt
echo -e "From: \nSubject: Additional $num_new_files new photo(s) uploaded to photo frame\n\nNew files or pictures uploaded the folder being monitored." "$(<diff.txt)" | /usr/bin/ssmtp youremail@gmail.com, yourbossesemail@gmail.com
rm current.txt
rm prior.txt
rm diff.txt
fi


Please note that "current.txt" is a sorted version of the file "current_dir", which in turn is a list of the current files in the directory. Same with "prior.txt". Then "diff.txt" is a file listing anything different between "current.txt" and "prior.txt". The .txt files are temporary, and get deleted as soon as the email is sent out. I'm sure there's a more elegant way to do this, but it should work.
mzn
Trainee
Trainee
Posts: 10
Joined: Mon Aug 01, 2016 6:46 pm

Re: Email notification about new file upload (Shared Folder)?

Postby mzn » Wed Jun 07, 2017 10:02 pm

Have you included the rest of the script from above?

Return to “Feature Requests & Product Improvement Suggestions”

Who is online

Users browsing this forum: No registered users and 3 guests