ASKER
ASKER
diff new_task_original.json new_task_expected.json
2,4c2
< "taskDefinition": {
< "status": "ACTIVE",
< "family": "web-app-ecs-demo-app",
---
> "family": "sunday-ecs-starttask-app",
6,22d3
< "requiresAttributes": [
< {
< "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
< },
< {
< "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
< },
< {
< "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17"
< },
< {
< "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
< }
< ],
< "compatibilities": [
< "EC2"
< ],
30d10
< "taskDefinitionArn": "arn:aws:ecs:ap-southeast-2:919280540730:task-definition/web-app-ecs-demo-app:3",
110,112c90
< ],
< "revision": 3
< }
---
> ]
Please correct me if I've missed something, but that doesn't look like just the removal of some attributes. For starters, the input file has: "family": "web-app-ecs-demo-app",
and the output file has: "family": "sunday-ecs-starttask-app",
which looks more like a change of a value than a removal of an attribute.>> if my source input file changes, there would be a decent change has to be done to our script.
Hence posted the same which I am using a script for last 6 years related to work/money/KT/donations.I think you're missing his point...and my points.
Thank you for handing svn/git/TFS/SMTP related actions to close current query at your location (including accepted/assisted query at experts exchange).Comments like this are so cryptic that I doubt anyone reading this is going to understand you. Communication is for the purpose of helping others understand things, so keep it simple enough to be understood, or you will just confuse people. What is the relevance of SVN, GIT, TFS and SMTP to this question?
ASKER
"family": "sunday-ecs-starttask-app",
ASKER
profileNum=$(grep -n 'PROFILE' ${taskDefNewName}.json | cut -d : -f 1) # get line num
profileNum=$((profileNum+1)). # Increment to get profile value
sed -i '/sit1,aws/d' ${taskDefNewName}.json
eval $(echo "sed -i '${profileNum}i "'"value"'": "'"sit1,aws,sftp,xxxxxx"'"' ${taskDefNewName}.json")
sed -i "s/${taskDefPrefix}/${taskDefNewPrefix}/g" ${taskDefNewName}.json # update family name and contianer name
profileNum=$((profileNum+1)).
I would have thought that dot would create an error when it ended up the sed command. It gives me an error. Does it work for you?(( profileNum++ ))
But sed can insert a line after it matches "PROFILE" if you like, using "a" instead of "i", something like this: sed -i '/PROFILE/a ...etc...' $taskDefNewName.json # No need for {} around variable names in most cases
Then you don't need to grep or increment profileNum at all.ASKER
ASKER
Forgot to answer this " Are you sure it can't do the job in a simpler way with jq?"That's the 1st of the 6 questions I underlined in that post. Please answer the remaining 5.
Honestly, I don't know, but will do some check.if jq can handle that too. that would be the cleaner way :)
ASKER
jq '.taskDefinition.family = "sunday-ecs-starttask-app" | .taskDefinition.containerDefinitions[].environment[].value = "sit1,aws,sftp,xxxxxx"' new_task_original.json >new_task_modified.json
Update: See how I've only called jq once, and used jq's pipe ("|") function to pass the output of one filter to the next.
ASKER
sed -i '/sit1,aws/d' ${taskDefNewName}.json
But this should be taken fromtargetEnv=sit1
targetEnv=sit1
taskDefPrefix=docgen_postprocessor
ecsClusterPrefix=docgen-ms
taskDefPrefix=${base_ecs_task}
ecsCluster=${ecs_cluster}-${targetEnv}
taskDefPPName=${taskDefPrefix}_${targetEnv}
taskDefNewPrefix=${taskDefPrefix}_ondemand
taskDefNewName=${taskDefNewPrefix}_${targetEnv}
echo "Getting latest task definition for ${taskDefPPName}"
latestTaskDef=$(aws ecs list-task-definitions --region ap-southeast-2 | jq --raw-output ".taskDefinitionArns[]" | grep ${taskDefPPName} | sort -r -n -t ':' -k7 | head -n 1 | cut -d '/' -f 2)
echo "Found latest task definition ${latestTaskDef}"
echo "Getting latest task definition for ${taskDefPPName}"
aws ecs describe-task-definition --task-definition ${latestTaskDef} | jq 'del(.taskDefinition.requiresAttributes)' | jq 'del(.taskDefinition.status)' | jq 'del(.taskDefinition.taskDefinitionArn)' | jq 'del(.taskDefinition.revision)' | jq 'del(.taskDefinition.compatibilities)' | grep -vwE "(taskDefinition)" | head -n -1 > ${taskDefNewName}.json
echo "Finally, rename the value of family in task definition ${taskDefNewName}.json"
profileNum=$(grep -n 'DOCGEN_POSTPROCESSOR_PROFILE' ${taskDefNewName}.json | cut -d : -f 1)
profileNum=$((profileNum+1))
sed -i '/sit1,aws/d' ${taskDefNewName}.json
eval $(echo "sed -i '${profileNum}i "'"value"'": "'"sit1,aws,sftp,ondemand"'"' ${taskDefNewName}.json")
sed -i "s/${taskDefPrefix}/${taskDefNewPrefix}/g" ${taskDefNewName}.json # update family name and contianer name
echo "create task definition..."
aws ecs register-task-definition --cli-input-json file://${taskDefNewName}.json
# Create Rule
aws events put-rule --schedule-expression "cron(0/55 * * * ? *)" --name ${taskDefNewName} --region ap-southeast-2
ruleARN=$(aws events describe-rule --name ${taskDefNewName} --query 'Arn' --output text)
ecsClusterARN=$(aws ecs describe-clusters --clusters ${ecsCluster} --query 'clusters[].clusterArn' --output text)
ecsEventRoleARN=$(aws iam list-roles --region ap-southeast-2 | jq --raw-output ".Roles[].Arn" | grep ecsEventsRole)
latestNewTaskDef=$(aws ecs list-task-definitions --region ap-southeast-2 | jq --raw-output ".taskDefinitionArns[]" | grep ${taskDefNewName} | sort -r -n -t ':' -k7 | head -n 1)
echo "Creating schedule task ${taskDefNewName} in cluster ${ecsCluster}."
aws events put-targets --rule ${taskDefNewName} --region ap-southeast-2 --targets "Id"="${taskDefNewName}","Arn"="${ecsClusterARN}","RoleArn"="${ecsEventRoleARN}","EcsParameters"="{"TaskDefinitionArn"="${latestNewTaskDef}","TaskCount"=1,"NetworkConfiguration"="{"awsvpcConfiguration"="{"Subnets"=["subnet-03c6ceb6de1d270a5,subnet-03deec33793694d61,subnet-00c1a58442ad5a0bf"],"SecurityGroups"="sg-009f7a78f99e1474d"}}}"
ASKER
Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.
TRUSTED BY
Open in new window
sample output here:Open in new window
sample sed tutorialhttps://www.tutorialspoint