LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-13-2017, 10:15 AM   #1
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 9, SH4, Debian
Posts: 367

Rep: Reputation: 8
inotifywait only in specific dir, specific type of file


I spent a lot of time but no lucky.
I want to trigger action when in specific dir (and only in that dir) will be new file. This dir contains films so transmission of such file take several minutes. It could be MKV or MP4 file. I want to trigger action when file will be closed, that is transmission ends. Other types of files in this dir should be ignored by inotifywait.
Any advice how looks like proper syntax of such inotifywait command?
 
Old 05-13-2017, 10:23 AM   #2
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
See https://linux.die.net/man/1/inotifywait
 
Old 05-13-2017, 10:44 AM   #3
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 9, SH4, Debian
Posts: 367

Original Poster
Rep: Reputation: 8
I read it but if I want specify wildcards in filename (like *.mkv) it does not work. Look at the command line I use. Where is an error?

Code:
inotifywait -e close_write /path_to_dir/*.mkv
 
Old 05-13-2017, 10:47 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,679

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
Although you should be able to find some examples here is a basic bash script to watch a directory. You can add code to test for mkv or mk4 extension.

Code:
#!/bin/bash
/usr/bin/inotifywait -mq -e close_write --format %f /dir/to/watch | while IFS= read -r file; do
  echo $file
  Do something constructive here...
done
Your command fails because you can not watch something that does not already exist as far as I know.

Last edited by michaelk; 05-13-2017 at 11:00 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating csv file with specific values in specific fields rap Programming 1 08-03-2016 04:40 AM
How to get file path for specific type of file on my server? Ferodactyl Linux - Newbie 5 08-08-2013 08:21 AM
wget, download specific links into specific file names Si14 Linux - Software 1 04-30-2013 01:42 AM
[SOLVED] Search for specific type of file recursively koshy Linux - Newbie 4 03-02-2013 03:15 AM
[SOLVED] how to make grep to search a pattern in only specific file type mq15 Linux - Newbie 7 03-07-2010 09:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration