I have a video encoding script that I would like to run as soon as a file is moved into a specific directory.
If I use something like inotify, how do I ensure that the file isn't encoded until it is done moving?
I've considered doing something like:
However, how do I get step #2 to work properly and only run once #1 is complete?
I am using Ubuntu Server 11.10 and I'd like to use bash, but I could be persuaded to use Python if that'd simplify issues.
I am not "downloading" files into this directory, per se; rather I will be using rsync the vast majority of the time.
Additionally, this Ubuntu Server is running on a VM.
I have my main file storage mounted via NFS from a FreeBSD server.
Use the mv command to move a file from one location to another. To move a file on a computer with a graphical interface, you open the folder where the file is currently located, and then open another window to the folder you want to move the file into. Finally, you drag and drop the file from one to the other.
To move a file, hold down the Shift key while dragging. You can also use the middle mouse button to drag files. In this case, gThumb will ask you if you wish to copy the files, move the files, or cancel the operation. Select the files to be transferred, right-click on the selection, and choose Copy to... or Move to....
How do I Drag and Drop? By default, if you left-click and HOLD the left mouse or touchpad button while moving your mouse pointer to a different folder location on the same drive, when you release the left mouse button the file will be moved to the new location where you released the mouse button.
Difference between copying and moving files / foldersCopying – make a duplicate of the selected file or folder and place it in another location. Moving – move the original files or folder from one place to another (change the destination). The move deletes the original file or folder, while copy creates a duplicate.
The easiest way would be to download using a program like wget
or curl
that doesn't exit until the file is done downloading. Failing that, I'm not sure if it's the absolute best solution, but you could use a script that loops, checking whether the file is open using lsof
and grep
:
while lsof | grep /path/to/download >/dev/null; do sleep 5; done
mv /path/to/download /path/to/encode/dir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With