<p>I am trying to run an AWS CLI command in my pod. As the pod may take some time to complete i am trying to run it in the background
Here is my command</p>
<pre><code>kubectl -it exec  &lt;podname&gt; -- bash -c &quot;aws s3api list-objects --bucket bucketname-1 --query 'Contents[?StorageClass==\&quot;ONEZONE_IA\&quot;].[Key,StorageClass]' --output text &gt; /storage/ONEZONE_keys1.txt &amp;&quot;
</code></pre>
<p>when I run this command it becomes a defunct process
<a href="https://i.stack.imgur.com/Key3f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Key3f.png" alt="process" /></a></p>
<p>when I run the command without the <code>&amp;</code> in the end it works fine
But the process gets terminated once the terminal is closed</p>
<p>Ultimately I just want to run this command as a cron job every day</p>
<p>Not sure whats wrong ,or this whole process can be done in a better way</p>
<p>Any help is much appreciated, Thank you</p>

Tony Frank
<p>I think nohup can help on this scenario. Try to execute this command with &quot;nohup&quot;.</p>
<p>Ex-</p>
<blockquote>
<p>nohup  &quot;your command&quot; &gt; &quot;redirect file-name&quot; &amp;</p>
</blockquote>
