Download and view my resume (PDF)

Friday, August 20, 2010

Double-escape when using Chef "Script" resource


Today I had a frustrating problem getting a functional shell script to execute from a Chef recipe using the Script resource.

The code conditionally executed a sed command to modify a configuration file (in my case, /etc/rcp). The code ran perfectly when executed as a bash script, or when the sed command was issued on the command line. Inside a Script resource, however, the sed command always returned empty string.

Perhaps this should have been immediately obvious, but I spent quite a bit of time redirecting outputs and debugging the regular expression in the sed command before I realized that where I had used a backslash to escape special regular-expression characters, I needed to use double backslashes so that one backslash survives the Ruby interpreter.

No comments:

Post a Comment