0

To explain the question: my server (NAS) sleeps when it is not used and I want to keep it this way. However, when someone uploads a photo folder, it wakes up and processes the upload.

I would like to notify a group of people when someone uploads a new folder, I would love to have a "cron", which triggers on a special event "someone uploads new folder" or a "cron" which runs only when the NAS is awake, because normally when I schedule the cron to be launched every 4 hours, the server sleeeps and then wakes up (every 4 hours) -- which I do not want.

The "upload process" (generating thumbnails) is a third-party application and I cannot modify this. What I need is to trigger the notify script at the right time (and not to wake a sleeping NAS).

  • Your best bet is inotify. You can't use it from a script but you can use it to monitor the upload folder for changes and receive events on change. – Ginnungagap Dec 04 '16 at 22:25
  • What do you mean by sleeping? If it is still running scheduled cron jobs and responds to network traffic, it doesn't seem like it is sleeping. – kasperd Dec 04 '16 at 23:20
  • It is Synology NAS. From what I know, the HDD is off when it is as I say "sleeping", it is possible to wake it on LAN and when a task is scheduled -- than the HDD starts rotating and the system goes up -- the same happens when I try to log in to web management / SSH -- if it is "sleeping" I have to wait a couple of seconds for it to wake up, then it operates normally – user52107 Dec 05 '16 at 07:03

1 Answers1

0

Cron is a time based job scheduler rather than event based. I'm not aware of a way to make Cron do something in response to an event.

In seems to me that you probably want a bash script instead. Depending upon your NAS's operating system, you should be able have a bash script run automatically on resume (wake from sleep). In Ubuntu for instance, you'd use pm-utils to do this: https://askubuntu.com/questions/226278/run-script-on-wakeup your OS may vary.

The script you run on wake could use bash's IF and test statement to check for the existence of a file or folder, sending an email if it is found. For more info on using IF statements in this way check here: https://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html

leftcase
  • 710
  • 3
  • 10
  • 18
  • This is a nice feature, but if I understand it correctly, I would have to wait until it goes asleep again and then when someone actually wakes it up (then the "script on wakeup" is launched). I actually need something like "script on going asleep". -- If I upload photos on Monday and the first visitor comes on Wednesday, the notification is than sent on Wednesday. – user52107 Dec 05 '16 at 07:06