<p>In my k8 cluster I have pods running that the pod name contains the word &quot;inventory&quot; (actually 2pods with this name)
I need to write a shell script to delete deployment and re-deploy and then it should check the specific pod is running or not and then display a message.
Here is what I tried.</p>
<pre><code>#!/bin/bash
cd /apps/application/application_yamls_develop/deployment-artifacts/inventory-service
kubectl delete -f inventory-service.yaml -n back-end
kubectl apply -f inventory-service.yaml -n back-end
sleep 20

pod_name=&quot;inventory&quot;
namespace=&quot;back-end&quot;

# Get the pod status
pod_status=$(kubectl get pods -n &quot;$namespace&quot; -o jsonpath=&quot;{.items[?(@.metadata.name.includes('$pod_name'))].status.phase}&quot;)

# Check if any matching pod is running
if [[ -n &quot;$pod_status&quot; ]]; then
  echo &quot;Pod running&quot;
else
  echo &quot;Pod not running&quot;
fi
</code></pre>
<p>But this is giving the bellow error.</p>
<pre><code>error: error parsing jsonpath {.items[?(@.metadata.name.includes('inventory'))].status.phase}, unclosed array expect ]
</code></pre>
<p>Can someone please pointout the issue.</p>
<p>Thanks..!</p>

Kasun Wimaladarma
<p>Can you try this</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>#!/bin/bash

pod_name="devopslk"
namespace="devops"

# Get the pod status
pod_status=$(kubectl get pod "$pod_name" -n "$namespace" -o jsonpath='{.status.phase}')

# Check if any matching pod is running
if [[ -n "$pod_status" ]]; then
  echo "Pod running"
else
  echo "Pod not running, Current status: $pod_status"
fi</code></pre>
</div>
</div>
</p>
<p><a href="https://i.stack.imgur.com/UhZZ7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UhZZ7.png" alt="enter image description here" /></a></p>
