Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Launching a shell script on file operations [solved]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
ultraViolet
Apprentice
Apprentice


Joined: 03 Apr 2004
Posts: 280
Location: Lyon, France

PostPosted: Sun Apr 27, 2008 12:06 pm    Post subject: Launching a shell script on file operations [solved] Reply with quote

Hi,

I would like to launch a script each time a copy, delete, rename, move operation occurs on a given folder. I know it is possible with crontab but I would like to launch the script only if it is necessary, and I would like this script to be activated in real time.

Thank for any answer


Last edited by ultraViolet on Sun Apr 27, 2008 7:07 pm; edited 1 time in total
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Sun Apr 27, 2008 6:15 pm    Post subject: Reply with quote

I do this to show a popup notification when a new file arrives via mldonkey.

First, you need this:

Code:

emerge sys-fs/inotify-tools


Now, you can run something like this:

Code:

inotifywait -mrq --excludei .*\.tmp --format "%f" --event create --event move /storage/downloads/ | while read newfile; do (notify-send --expire-time=30000 --icon=/usr/share/icons/hicolor/32x32/apps/kmldonkey.png "Nuevo archivo recibido:" "$newfile"&); done


Now, you can test it by doing a simple touch on any file inside that directory, for example:

Code:

touch /storage/downloads/test


And a popup should show, saying that the file called "test" has just arrived. Of course, you can use any other notifier, like kdialog for example, or trigger any other arbitrary action. That's just an example.
Back to top
View user's profile Send private message
ultraViolet
Apprentice
Apprentice


Joined: 03 Apr 2004
Posts: 280
Location: Lyon, France

PostPosted: Sun Apr 27, 2008 7:07 pm    Post subject: Reply with quote

Thanks. Exactly what I needed, opening all possibilities. I want this to make a folder with shorcuts revealing new items or automatically sorting files depending on imdb data.

Thanks again
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum