<p>I'm trying to check if a particular cronjob is active or not through a shell script to perform some action if the job is not active. I tried using field-selector attribute for cronjob and the job created by the cron job as below</p>
<pre><code>kubectl get cronjobs --field-selector status.active==1
kubectl get jobs --field-selector status.succeeded==1
</code></pre>
<p>But getting these field selectors are not supported. Is there any other field/way where I can check if the cronjob is active?</p>

Manoj kumar
<p>You could also set a label on your cronjob (and set the same label on the <code>template</code> part of the cronjob so it propagates to the underlying job that gets created), and then use that to select via:</p>
<p><code>kubectl get cronjob -l label=value</code></p>
<p><code>kubectl get job -l label=value</code></p>
<p>Yes, it doesn't select by active/disabled state, but you did mention in your question you were checking a particular cronjob, so this would bring up the details of the specific cronjob or job for you to check</p>
<p>To get the actual suspend state of the cronjob, you could pipe it to jq</p>
<p><code>kubectl get cronjob cronjob-name | jq .items[0].spec.suspend</code></p>
<p>This will give you &quot;false&quot; or &quot;true&quot; if the cronjob is suspended or not:</p>
<pre><code>$ kubectl get cronjob -n test
NAME      SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
api       */5 * * * *   False     0        78s             5m53s
</code></pre>
<pre><code>$ kubectl get cronjob -n test api -o json | jq .spec.suspend
false
</code></pre>
<p>You could probably also do this with <code>jsonpath</code></p>
<pre><code>kubectl get cronjob -n test api -o jsonpath=&quot;{.spec.suspend}&quot;
</code></pre>
<p>From comment below, you use can <code>active</code> (i.e. currently running) , to see how many jobs are active (will be 0 if you don't have anything running)</p>
<p><code>kubectl get cronjob -n test api -o jsonpath=&quot;{.spec.active}&quot;</code></p>
