0

I would like to have a simple script to notify the user in the screen, each time a new folder or file is created in a shared folder. The output should be like "You have a new file/folder named newfile/newfolder". I'm using this script, but I'm not able to put the newfile/newfolder name in zenity output.

while inotifywait -r -e create ~/Documents/Process
do
    zenity --warning -- ????
done

thks Djames

2

You can try a similar script:

while true
do
    fileName=$(inotifywait -r -e create ~/Documents/Process | sed -r 's/^.*CREATE(,ISDIR)*\s+(.*)$/\2/g')
    zenity --warning --text="You have a new file/folder named $fileName"
done

The fileName variable holds the extracted file name that inotifywait detects and outputs. (It is filtered from the output by using a sed command.)

Then the $fileName is displayed by zenity using the --text= switch.

These two lines run in an endless loop to enable detection of other creation events. Use CTRL + C to abort the watch.

  • thks! It works!, but I'll make some more tests to check if everything is ok! – DJames Jun 8 '12 at 8:35
  • I'm glad you've found it useful! I've tested it with some weird filenames, but make sure to comment on any problems. – lgarzo Jun 8 '12 at 8:40
  • Ok, a little more complicated. I've looking in sed manual, what you have donne, but I'could understand quite well...the inotify can have 3 outputs: "CREATE" (file), "CREATE,ISDIR" (directory), or empty when deleting file ou folder. The important output is the text right next to "CREATE" or "CREATE,ISDIR". Can you help? thks! – DJames Jun 8 '12 at 19:03
  • @Djames Updated for directory detection, sorry for the inconvenience. – lgarzo Jun 9 '12 at 13:43
  • thks very much, it's working! ;) – DJames Jun 11 '12 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.