2

I've been making progress, but I'm not sure how to proceed from here. I'm using inotifywait with the -d (daemon) switch to output a file that lists the video files that are put into the watched folder.

The list is desired because adjusting volume levels and recoding is very time consuming and I don't want to miss any events. My problem lies in how to actually manipulate the data into something I can use in a zsh script. The individual lines use the following format

/path/to/file containing/white spaces/ CLOSE_WRITE,CLOSE file name with white spaces

What I need is

/path/to/file\ containing/white\ spaces/filename\ with\ white\ spaces.extension

The path, changes as does the number of levels of subfolders, as do the file names. What is consistent is ** CLOSE_WRITE,CLOSE ** (one white space preceding and one following) and if somebody would be kind enough to educate me on how to remove this portion of the line in a zsh script I think (hope, actually) I know enough that I can precede the remaining white spaces with back slashes and remove the line after it is no longer needed using Vim from the command line with a snippet I came across.

I have most of what I need, in fact I've written scripts that will chug along for hours automatically converting files OR adjusting volume levels, I just need this to tie it all together (I even have a plan to check for unconverted files at boot - plus figure out how to create an atomic file/folder lock, create a new tmux session so I can logout but leave my computer running - at least until I repair my desktop and maybe even learn to use parallel, but that all comes later)

Any and all help greatly appreciated.

1
  • If you look a bit farther you'll find that I've managed to get my stuff straightened out. While the answers I received may not have been bang on, they did prompt me to go over what I knew and now I have a whole new set of problems to figure out. Not asking quite yet. One of the biggest problems I face is allowing my clinical depression turn my brain to mush - which is why I started to learn how to script in the first place.
    – Terry
    Jun 1, 2017 at 8:17

2 Answers 2

1

You could use the --format option to inotifywait to change the output format. This would just print the file names when files are closed, not the event type:

inotifywait -eclose_write -m --format "%w%f" -q /path/to/target/dir

It doesn't seem to support C-style escapes (\0) and insists on printing a newline at the end of each event, so I hope you don't have filenames with newlines in them.

4
  • I was hoping for a more elegant solution to separate processes, but I think I can use your suggestion with a couple of different watches on the same file/folder. The first watch would create a list if one does not exist and add the file name to the end and then would be freed up to continue monitoring and reporting events. A second watch reporting on the same event would, after a brief sleep, look for said file list and spawn the process to begin conversion, etc.
    – Terry
    Apr 20, 2017 at 21:58
  • 1
    @Terry, Well you said "What is consistent is ** CLOSE_WRITE,CLOSE ** and if somebody would be kind enough to educate me on how to remove this portion of the line...", so that's what I thought you wanted. Sure, you could do the string editing in the shell (which I didn't), but I think it's better to format it at the source. And if you need it, you can still add the event to the format string with %e. I'd move it to the front for easier parsing. The question didn't show how you're processing the output, so it's quite hard to take that into account.
    – ilkkachu
    Apr 21, 2017 at 8:30
  • Sorry for not responding sooner, but I suffer from chronic depression and I've been through a rough time. You prompted me to go back over what I knew, discarded a lot of what I thought I knew, and then set everything aside. When I do that it seems that the back of my mind keeps playing with the problem. Now I think I've got a fairly good understanding of the whole inotify thing and no longer stare at the screen while lost in a fog. I am now able to put together a watch and can see how it all fits together.
    – Terry
    Jun 1, 2017 at 7:51
  • As for the naming problem I needed a way to separate the names of tv shows from the portion of the file name defining season and episode. All the files ended with the format 'S[0-9][0-9]E[0-9][0-9]' just before the extension. I happened across a 13-year-old script (talk about bitrot!) that I managed to tidy up and adapt to my needs. Now I can toss a mess of video files into one folder and sort them into ./name/name-season/foo. If anyone wants a copy, I'm happy to share. I really should open a github account to store my scripts. Thanks for your time.
    – Terry
    Jun 1, 2017 at 8:05
0

From man parallel:

EXAMPLE: GNU Parallel as dir processor

If you have a dir in which users drop files that needs to be processed you can do this on GNU/Linux (If you know what inotifywait is called on other platforms file a bug report):

inotifywait -qmre MOVED_TO -e CLOSE_WRITE --format %w%f my_dir |\
      parallel -u echo

This will run the command echo on each file put into my_dir or subdirs of my_dir.

You can of course use -S to distribute the jobs to remote computers:

inotifywait -qmre MOVED_TO -e CLOSE_WRITE --format %w%f my_dir |\
      parallel -S ..  -u echo

It sounds pretty close to what your hoping to do.

To learn GNU Parallel follow the "Reader's guide" at the beginning of "man parallel".

1
  • Wow! Have I ever fallen behind. My apologies for not making some sort of response sooner, but I'm a classic textbook example of a manic depressive (yes, I'm seeing a doctor for it), and to tell the truth this kind of slipped my mind. I still haven't tied all of my scripts into one bundle, but this does reveal a whole bunch of interesting possibilities. Thanks for taking the time to answer. I'm back working on it again and it looks like this will help.
    – Terry
    Jun 1, 2017 at 7:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .