3

This question is a bit more specific than related questions because of the following requirements:

  • I need a program to run when a new file is added to a folder using scp.
  • The file can only have a specific file extension .ssml.
  • The file name has to be used as an argument. ./sabdfl popey.ssml
  • Files will be rapidly added to the folder on a threaded machine, and so multiple instances of the program will have to be added. Obviously I will need to prevent execution of two instances on the same file. The file gets deleted by the program after its finished executing.
  • However, no more than n number of instances can be running at once, to ensure a thread is always free for running the machine.
  • The execution must halt when the server starts running out of physical drive space.

What is the best way to go about this on Ubuntu?

muru
  • 197,895
  • 55
  • 485
  • 740
Anon
  • 12,063
  • 23
  • 70
  • 124
  • 1
    If this very specific task can be done on Ubuntu, I will respect Ubuntu as never before. – Ad Infinitum Mar 22 '17 at 08:37
  • 2
    How quickly you need it to respond? I think it can be done easily using a cronjob to check the list of files in the folder every 1m or 5m and take action if new file be found – Mostafa Ahangarha Mar 22 '17 at 08:41
  • @MostafaAhangarha I don't mind using a cron job, however there is a downside given that the traffic to the folder will greatly vary. – Anon Mar 22 '17 at 08:43
  • @MostafaAhangarha an upside to the cron job (Any thing that is time based) is that it would make it easy to make sure the files are not run on by multiple instances. – Anon Mar 22 '17 at 08:46
  • 2
    @Adinfinitum please respect Ubuntu before hand, it can be done I would prefer a systemd service ;)... – George Udosen Mar 22 '17 at 08:51
  • 2
    Take a look at incron. – Jos Mar 22 '17 at 08:55
  • 1
    Can be done for sure using threads/queues in python, but I believe it is a job that exceeds what this site is for. What kind of numbers (of files/minute) are we talking about anyway? – Jacob Vlijm Mar 22 '17 at 08:56
  • 1
    Look at inotifywait: https://askubuntu.com/questions/541128/monitor-folder-contents-changes – ridgy Mar 22 '17 at 12:05
  • 1
    @ridgy inotifywait offers no option to create a controlled, multithreaded flow, which is needed if I understand the question correctly. Akiva, did you notice my question/comment? – Jacob Vlijm Mar 22 '17 at 12:25
  • @Jacob that's right - this is just a starting point; additional scripting is needed, or the inotify API must be used (man 7 inotify) to create a threaded program. – ridgy Mar 22 '17 at 12:31
  • @JacobVlijm I figured the scope would fall within ubuntu because we are dealing with SystemD and or Cron Jobs. Just about any programming language could do this... I suppose I could do this in Qt... – Anon Mar 22 '17 at 17:30
  • You don't need multiple process a single one can handle all the files in the directory. Cron boot job is best for me at least. – WinEunuuchs2Unix Mar 23 '17 at 14:52
  • @WinEunuuchs2Unix That totally depends on the number of files/time and the action to be taken on the files. Akiva, I asked for that info, but didn't get it yet? – Jacob Vlijm Mar 23 '17 at 22:00

0 Answers0