IT-Sheriff
IT-Sheriff

Reputation: 164

Chef throwing error in Execute resource

I am writing a very basic recipe to copy data from one folder to another. I wrote following code:

execute "file_sharing" do

command "copy "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webapps"; /Y;"

end

When I go to my node and try executing this command, it runs perfectly fine. But if I try to run this recipe I through Chef, It is throwing error. Screenshot of error is attached. Please have a look and suggest solution.![error

command "copy "X:\B2BPortal-0.0.1-SNAPSHOT.wa...
                ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: no .<digit> floating literal anymore; put 0 before dot
...ommand "copy "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-to...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tINTEGER
...mmand "copy "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tom...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tSTRING_BEG, expecting keyword_end
...:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apa...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tCONSTANT, expecting keyword_end
...2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apache...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: no .<digit> floating literal anymore; put 0 before dot
...HOT.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webap...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tINTEGER
...T.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webapps...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: no .<digit> floating literal anymore; put 0 before dot
...omcat-6.0.32\apache-tomcat-6.0.32\webapps"; /Y;"
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tINTEGER
...cat-6.0.32\apache-tomcat-6.0.32\webapps"; /Y;"

]1

Upvotes: 0

Views: 598

Answers (2)

cassianoleal
cassianoleal

Reputation: 2566

You have to either escape the double quotes AND the backslashes inside the command string, or wrap it in single quotes instead. Since you're not doing any variable interpolation there, I'd suggest the latter.

Try this:

execute "file_sharing" do
  command 'copy "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webapps" /Y;'
end

Upvotes: 0

coderanger
coderanger

Reputation: 54181

In Ruby, \ (backslash) is used for string escape sequences like \n and \t. You can either use \\ or single quotes ' since those don't process backslash escapes.

Upvotes: 1

Related Questions