0

This I need quotes in a cronjob which I am creating through a chef recipe but even though I escape the quotes they do not appear in the cronjob which is created.

bash "Add cron" do
  user root
  group root
  code <<-EOH
      (
        (crontab -l; echo "5 0 * * * /bin/find #{node['user']['dir']}/files/ -type f \\( -name \"*.csv\" -o -name \"*.csv.bad\" -o -name \"*.ctrl\" \\) -mtime +1 -print0 | xargs -0 gzip -f" ) | crontab -
       )     
  EOH
end

just to clarify the cron job I want to end up with should contain -name "*.csv"

but what I actually get is -name *.csv

Jacxel
  • 1,547
  • 7
  • 21
  • 33
  • any reason to not use the `crontab` resource instead ? – Tensibai Mar 30 '17 at 11:44
  • I'm editing recipes that were created by someone else, this is just how they did it. I did consider using that instead but I assume I should be able to do what I'm trying to here. – Jacxel Mar 30 '17 at 11:51
  • The single quote echo argument and keep double quotes within. that's just a bash problem at all. But really, that's brittle and make very few sense when there's resources handling that properly for you already. – Tensibai Mar 30 '17 at 12:12

1 Answers1

1
bash "Add cron" do
  user "root"
  group "root"
  code <<-EOH
      (
        (crontab -l; echo -e '5 0 * * * /bin/find /home/root/files/ -type f \\( -name \"*.csv\" -o -name \"*.csv.bad\" -o -name \"*.ctrl\" \\) -mtime +1 -print0 | xargs -0 gzip -f'
       )
  EOH
end

Use single quote instead of double here.

Jacxel
  • 1,547
  • 7
  • 21
  • 33
rusia.inc
  • 711
  • 5
  • 9
  • my fault, i have edited the code in an attempt to simplify the case, i removed a section of it which already uses single quotes, i have edited the example again. – Jacxel Mar 30 '17 at 13:34
  • i suppose i can swap the attriute declaration quotes for doubles – Jacxel Mar 30 '17 at 13:40
  • you mean to swap quote as in'' with quote in "" ?, If this is what you ask then yes, double quotes is more specifically used when need to do string interpolation in attribute declaration. – rusia.inc Mar 30 '17 at 15:45