Question: Sorry if a silly question.

I have a script that doesn't behave how it's intended even though a condition is met.

My script is something like this:

```sh
    state=$(Substate=running)

    systemctl show -p SubState someservice | while read output
    if [ $output = $state ];
    then
    echo "ok"
    else
    echo "not ok"
    fi 

```

I've tried declaring the state variable in different ways but non seem to work;

```sh
    state=$(Substate=running)
    state=Substate=running
    state="Substate=running"

```

also tried `[ $output = $state ] [ "$output" = "$state" ] [[ ]]` but nothing works.

I think I'm declaring the state variable wrong?

Can anybody point me in the right direction?

Many thanks in advance

Answer: 
This is due to a connectivity issue.

The [docs](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-configure-network.html) say the following:

> 
> For tasks on Fargate, in order for the task to pull the container image it must either use a public subnet and be assigned a public IP address or a private subnet that has a route to the internet or a NAT gateway that can route requests to the internet.
> 
> 
> 

So you need to make sure your task has a route to an internet gateway (i.e. it's in a Public subnet) or a NAT gateway.

Alternatively, if your service is in an isolated subnet, you need to create VPC endpoints for ECR and other services you need to call, as described in the [docs](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/vpc-endpoints.html):

> 
> To allow your tasks to pull private images from Amazon ECR, you must create the interface VPC endpoints for Amazon ECR.
> 
> 
> 

When you create a scheduled task, you also specify the networking options. The [docs](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/scheduled_tasks.html) mention this step:

> 
> (Optional) Expand Configure network configuration to specify a network configuration. This is required for tasks hosted on Fargate and for tasks using the awsvpc network mode.
> For Subnets, specify one or more subnet IDs.
> For Security groups, specify one or more security group IDs.
> For Auto-assign public IP, specify whether to assign a public IP address from your subnet to the task.
> 
> 
> 

So the networking configuration changed between the manually run task and the scheduled task. Refer to the above to figure out the needed settings for your case.
Need to use a gateway to follow the traffic from ECS to ECR. It can either Internet Gateway or NAT Gateway eventually which would be effecting cost factor.

But where we can resolve this scenario, by creating VPC Endpoints. Which maintains the traffic within the AWS Resources.

Endpoints Required for this would be :
S3 Gateway
ECR
ECS