0
votes

I have a string which will be used as command. Also before running that command I need to replace a string pattern with a variable value..

But is upon assigning I am getting command not found for all of the output lines.

I have tried putting the escape chars but not helping.

role-command="aws sts assume-role --role-arn  arn:aws:iam::<acct_id>:role/AWS-Role --role-session-name temp-aws-rolesession --output text --duration-seconds 3600 --query 'Credentials.[[join(`=`,[`AWS_ACCESS_KEY_ID`, AccessKeyId])],[join(`=`,[`AWS_SECRET_ACCESS_KEY`, SecretAccessKey])],[join(`=`,[`AWS_SESSION_TOKEN`, SessionToken])]]'"

bash: =: command not found bash: AWS_ACCESS_KEY_ID: command not found bash: =: command not found bash: AWS_SECRET_ACCESS_KEY: command not found bash: =: command not found bash: AWS_SESSION_TOKEN: command not found

bash: role-command=aws sts assume-role --role-arn arn:aws:iam::<acct_id>:role/AWS-Role --role-session-name temp-aws-rolesession --output text --duration-seconds 3600 --query 'Credentials.[[join(,[, AccessKeyId])],[join(,[, SecretAccessKey])],[join(,[, SessionToken])]]': No such file or directory

And the I was suppose to do sed -i s/<acct_id>/97476414123/g ${role-command}

How can I achieve this?

I have tried even below:

role-command="aws sts assume-role --role-arn  arn:aws:iam::<acct_id>:role/AWS-Role --role-session-name temp-aws-rolesession --output text --duration-seconds 3600 --query 'Credentials.[[join(\`=\`,[\`AWS_ACCESS_KEY_ID\`, AccessKeyId])],[join(\`=\`,[\`AWS_SECRET_ACCESS_KEY\`, SecretAccessKey])],[join(\`=\`,[\`AWS_SESSION_TOKEN\`, SessionToken])]]'"

Getting below:

bash: role-command=aws sts assume-role --role-arn  arn:aws:iam::<acct_id>:role/AWS-Role --role-session-name temp-aws-rolesession --output text --duration-seconds 3600 --query 'Credentials.[[join(`=`,[`AWS_ACCESS_KEY_ID`, AccessKeyId])],[join(`=`,[`AWS_SECRET_ACCESS_KEY`, SecretAccessKey])],[join(`=`,[`AWS_SESSION_TOKEN`, SessionToken])]]': No such file or directory

Regards, SA

1
I have got this right. I can confirm its done now. ............................ y="$(echo "aws sts assume-role --role-arn arn:aws:iam::<acct_id>:role/AWS-Role --role-session-name role-session --output text --duration-seconds 3600 --query 'Credentials.[[join(`=`,[`AWS_ACCESS_KEY_ID`, AccessKeyId])],[join(`=`,[`AWS_SECRET_ACCESS_KEY`, SecretAccessKey])],[join(`=`,[`AWS_SESSION_TOKEN`, SessionToken])]]'" |sed 's/<acct_id>/56787654567/g')"abhiks

1 Answers

0
votes

I have got this right. I can confirm its done now

y="$(echo "aws sts assume-role --role-arn arn:aws:iam::<acct_id>:role/AWS-Role --role-session-name role-session --output text --duration-seconds 3600 --query 'Credentials.[[join(`=`,[`AWS_ACCESS_KEY_ID`, AccessKeyId])],[join(`=`,[`AWS_SECRET_ACCESS_KEY`, SecretAccessKey])],[join(`=`,[`AWS_SESSION_TOKEN`, SessionToken])]]'" |sed 's/<acct_id>/56787654567/g')"