You could use something like fanotify on Linux to do this.  If you install
the inotify-utils package (EL7) you get a utility called "inotifywait" that
notifies you of filesystem events.  You can use this trigger an action when
a filesystem event happens - for example, a file is written and closed -
and then do something with that file.  Here's an example of a script that I
have written that does this:

==
#!/usr/bin/bash

TYPE=$1
DIR=$2

shopt -s nocasematch
while true; do
  FILE=`inotifywait -r -e close_write --format %f $DIR`
  FILENAME=$(basename ${FILE})
  if ! [[ $FILE =~ \.csv$ ]]; then
    echo Removing non-csv ${FILE}
    mv ${FILE} /data/csv/broken/${TYPE}/
    continue
  fi
  dos2unix -n /tmp/${FILENAME} ${FILE} && rm ${FILE}
  /usr/local/bin/parse.sh $TYPE /tmp/${FILENAME} &

done
==

You can see that the script does a few things:
- Turns off case-sensitivity (my files are coming from Windows :-)
- Starts an infinite while loop
- Sets the variable FILE to the output of the command "inotifywait -r -e
close_write --format %f $DIR".  The "inotifywait" command watches for the
specified event (close_write) on a certain file or directory ($DIR) and
then returns the location and name of the file (whatever is specified by
--format).
- Gets the filename of the file
- Checks to make sure it's a CSV, if not, move it to a "broken" folder
- Does dos2unix conversion on it (again with the Windoze)
- Runs the script that parses the actual file.
- Lather, rinse, and repeat :-)

This could easily be adapted to handle recordings:

==
#!/usr/bin/bash

RECORDINGS=$1
ENCODED=$2

cd $ENCODED

while true; do
  FILE=`inotifywait -r -e close_write --format %f $RECORDINGS`
  /path/to/guacenc $FILE &

done
==

I've not tested this, so it may need some tweaking, but essentially it
should take two arguments - the path to the original recordings ($1) and
the path where you want the recordings to end up ($2), cds to the directory
where the encoded files will end up, and then watches events in the
recordings directory and runs the guacenc command (in the background) on
anything that gets written and closed in that directory.  You do have to be
careful with this - for example, if you put the recordings and encoded
files in the same directory, you could end up with a script that kicks off
an endless loop of guacenc commands on the already-encoded files, which
would be bad :-).

In my case, with the original script, I have a systemd service that starts
the script and makes sure that it stays running, and then inotifywait
handles the rest.

I'm sure there are even better ways to do this writing your own C
application to leverage fanotify, rather than just a shell script, but this
is a quick-and-dirty solution.

-Nick

On Wed, Apr 29, 2020 at 8:29 AM Sean Reid <[email protected]> wrote:

> Hi Syazin,
>
> There isn't a built-in way to do what you're asking, but it may be
> possible to do with a cron job. The cron job could run everyday,
> encoding all the files with a timestamp from the previous day. Then
> each day, you'd have the recordings from the previous day already
> encoded for you.
>
> Sean
>
> On Wed, Apr 29, 2020 at 12:40 AM Syazrin Saruddin <[email protected]> wrote:
> >
> > Hello all,
> >
> >
> >
> > Recently I done setup a connection, the only way to encode the recording
> session to m4v is by using manual guacenc cmd. Can you suggest an idea how
> to automatically convert the recording session immediately after disconnect?
> >
> >
> >
> > The path is /mnt/guacamole/recordings and to move to another dir
> /mnt/guacamole/recordings/converted to format yyyy-mm for each folder.
> >
> >
> >
> > Thanks.
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to