1

I'm writing a script searching for directories in a subtree and appending them to incrontab. I can even add folder names with blanks by escaping those with a backslash:

/path/to/observed\ directory IN_ALL_EVENTS /path/to/script.sh "\$@" "\$#" "\$%"

However, I have no clue how to add a folder containing a line feed character. None of the following works:

/path/to/observed\ndirectory IN_ALL_EVENTS /path/to/script.sh "\$@" "\$#" "\$%"

/path/to/observed\
directory IN_ALL_EVENTS /path/to/script.sh "\$@" "\$#" "\$%"

"/path/to/observed
directory IN_ALL_EVENTS /path/to/script.sh" "\$@" "\$#" "\$%"

Is there any possibility to get it work?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Pinke Helga
  • 321
  • 1
  • 2
  • 10
  • I suggest someone to create a tag "incrontab" and/or "incrond". I am not able to do so due to low reputation yet. – Pinke Helga Jun 16 '16 at 03:29
  • That depends entirely on how `incrond` parses its configuration file; you could look into the source to see how the parser behaves. I'd assume that it simply splits the file into lines by looking for line breaks, and that it doesn't interpret C escape sequences like `\n`. Is it that important to be able to monitor paths with newlines in it? They should be very rare, why not just skip them when generating the config? – Martin von Wittich Jun 16 '16 at 08:46
  • @MartinvonWittich I've thought about skipping as the last choice. However, I like to stay generic when coding a basic reusable solution. I'm afraid you are right and there won't be any way to get around the issue. – Pinke Helga Jun 16 '16 at 20:25

1 Answers1

1

Late, I know, but faced with this situation I would make a soft link to the directory with an acceptable name without extra characters, and then use that in the incron table.

$ ln -s /path/to/"My Dir With Funny Chars" /path/to/mydirwithoutfunnychars

and

incrontab -e
/path/to/mydirwithoutfunnychars IN_CREATE /path/to/do_this.sh $1 $2
u628898
  • 23
  • 3