0

I want to update many instances, so I have made a script with this command:

aws ssm send-command --instance-ids "$y" --document-name AWS-RunShellScript --parameters commands='yum -y update; needs-restarting -r; if \[ $? -eq 1 \]; then exit 194' --cloud-watch-output-config "CloudWatchOutputEnabled=true"

Instead of running the command on the machines specified by $y, it says: Error parsing parameter '--parameters': Expected: ',', received: ']' for input: commands=yum -y update; needs-restarting -r; if \[ 252 -eq 1 \]; then exit 194; else exit 0; fi

Note that the $? is referenced as 252 for some reason.

Casey
  • 444
  • 1
  • 7
  • 22
  • Does the bash commands work when you execute them manually? – Marcin Feb 14 '23 at 23:58
  • Yes it works locally. If I run the command, it exits the terminal. – Casey Feb 15 '23 at 03:42
  • (I'm not running amazon linux which has the needs-restarting utility). – Casey Feb 15 '23 at 03:48
  • `$?` expanding to `252` suggests the command is going through some sort of preprecessing/additional parsing step before it's executed. Is it being sent over `ssh`, stored in a variable, or anything like that? – Gordon Davisson Feb 18 '23 at 22:51

1 Answers1

1

Try putting double quotes around the value for --parameters:

aws ssm send-command --instance-ids "$y" --document-name AWS-RunShellScript --parameters "commands='yum -y update; needs-restarting -r; if \[ $? -eq 1 \]; then exit 194'" --cloud-watch-output-config "CloudWatchOutputEnabled=true"

See the examples in the aws-cli reference.