nrider
nrider

Reputation: 117

Run a bash script when new file directory?

So I have a folder on linux server where files are uploaded. However these files (mp3) need to be altered automatically once they have been uploaded.

For example I have found a python module which can modify the tags in mp3 files within a folder. However this module and the specific tag related command needs to be executed when a new file is uploaded..automatically.

Is this something that a bash script would be capable of achieving and if so what is needed to achieve this? I have read about inotify and similar but am still unsure if this is the best method.

Any input would be appreciated.

Thanks.

Upvotes: 2

Views: 456

Answers (2)

You could also use inotify(7) facilities, e.g. thru incron. As the documentation of incron explains, you probably want

 /your/directory IN_CLOSE_WRITE /path/to/my_script.sh $@/$#

as an incron job entry.

Upvotes: 5

James Mills
James Mills

Reputation: 19050

What you are after is something like watchdog

From their examples you can use watchdog's command-line tool like this:

watchmedo shell-command \
    --patterns="*.mp3" \
    --recursive \
    --command='/path/to/my_script.sh "${watch_src_path}"' \
    .

Upvotes: 1

Related Questions