Skip to main content
edited tags; edited tags
Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Source Link
ryekayo
  • 4.8k
  • 10
  • 46
  • 67

echoing Command to cron.d

I am trying to append/echo a command to cron.d. However, when running the script that echoes the command:

echo */2 * * * * /usr/bin/aws ssm-send-command --document-name "AWS-RunShellScript" --parameters '{"commands":["echo {{ssm:/mr2/cloudwatch-custom}}"]"}' --instance-ids "$INSTANCE_ID" --region us-east-1 >> /etc/cron.d/lvm_disk_space 

I cat out the file that it writes to and it has this:

*/2 boot-finished cloud-config.txt datasource handlers obj.pkl scripts sem user-data.txt user-data.txt.i vendor-data.txt vendor-data.txt.i boot-finished cloud-config.txt datasource handlers obj.pkl scripts sem user-data.txt user-data.txt.i vendor-data.txt vendor-data.txt.i boot-finished cloud-config.txt datasource handlers obj.pkl scripts sem user-data.txt user-data.txt.i vendor-data.txt vendor-data.txt.i boot-finished cloud-config.txt datasource handlers obj.pkl scripts sem user-data.txt user-data.txt.i vendor-data.txt vendor-data.txt.i /usr/bin/aws ssm-send-command --document-name AWS-RunShellScript --parameters {"commands":["echo {{ssm:/mr2/cloudwatch-custom}}"]"} --instance-ids --region us-east-1 

I'm assuming the * is messing things up. When I try to wrap it in quotes, I always get:

echo "*/2 * * * * /usr/bin/aws ssm-send-command --document-name "AWS-RunShellScript" --parameters '{"commands":["echo {{ssm:/mr2/cloudwatch-custom}}"]"}' --instance-ids "$INSTANCE_ID" --region us-east-1" >> /etc/cron.d/lvm_disk_space ./user-data.txt: line 30: unexpected EOF while looking for matching `"' ./user-data.txt: line 31: syntax error: unexpected end of file 

Is there a safe way to escape quotes?