1

I have a windows application will create a .xml file and upload it to a folder on my Linux server. I need a way to watch for this new file, its filename would be something like "004job.xml", "012job.xml" etc,etc. The filename is different every time. After the file is detected, a script would be run with the new file as its command line variable. Like this "/home/project/scripts/renderjob.sh /home/project/jobs/012job.xml". The script will do some actions based on the contents of the .xml file and the last action is to delete the .xml file.

Its also important that only one instance of this script is running at a time. but that is a horse of a different color.

Thanks for reading.

  • This might help: [How to continuosly monitor the directory using dnotify /inotify command](http://stackoverflow.com/q/7566569/3776858) – Cyrus May 08 '16 at 17:20

1 Answers1

0

Briefly:

After the file is detected, a script would be run with the new file as its command line variable.

https://unix.stackexchange.com/questions/273556/when-a-particular-file-arrives-then-execute-a-procedure-using-shell-script/273563#273563

Its also important that only one instance of this script is running at a time.

Use flock in your script in this way: https://unix.stackexchange.com/questions/274498/performing-atomic-write-operations-in-a-file-in-bash/274499#274499. Insert watching for your file inside the flock:

(
    flock -s 200

    res=$(inotifywait $DIR)
    # other actions

) 200>/var/lock/myscriptlock 
Community
  • 1
  • 1
  • This works somewhat. But how can pass just the filename created to the script. The $RES contains the event "/home/project/jobs/ CREATE 34job.xml. I just need the $RES to contain only the filename created. And i need this to watch all the time, even after an event is triggered. Keep watching. Thanks – Randy Adams May 08 '16 at 18:47
  • 1) `how can pass just the filename created to the script?` Why not monitor file events for a folder? Are you expecting someone else creating files in the same folder? 2) `I just need the $RES to contain only the filename created.` Then use `basename` on Linux. 3) `And i need this to watch all the time, even after an event is triggered.` Then let your script do a loop –  May 08 '16 at 19:32