<p><a href="https://i.stack.imgur.com/rcm8B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rcm8B.png" alt="enter image description here" /></a></p>
<p>The picture above shows the list of all kubernetes pods I need to save to a text file (or multiple text files).</p>
<p>I need a command which:</p>
<ol>
<li><p>stores multiple pod logs into text files (or on single text file) - so far I have this command which stores one pod into one text file but this is not enough since I will have to spell out each pod name individually for every pod:</p>
<p>$ kubectl logs ipt-prodcat-db-kp-kkng2 -n ho-it-sst4-i-ie-enf &gt; latest.txt</p>
</li>
<li><p>I then need the command to send these files into a python script where it will check for various strings - so far this works but if this could be included with the above command then that would be extremely useful:</p>
<p>python CheckLogs.py latest.txt latest2.txt</p>
</li>
</ol>
<p>Is it possible to do either (1) or both (1) and (2) in a single command?</p>

marcz2007
<p>The simplest solution is to create a shell script that does exactly what you are looking for:</p>
<pre><code>#!/bin/sh

FILE=&quot;text1.txt&quot;
for p in $(kubectl get pods -o jsonpath=&quot;{.items[*].metadata.name}&quot;); do
    kubectl logs $p &gt;&gt; $FILE
done
</code></pre>
<p>With this script you will get the logs of all the pods in your namespace in a FILE.
You can even add <code>python CheckLogs.py latest.txt</code></p>
