Can you please let me know if this command is valid ?
kubectl get pods -A | awk {'printf "%s %s %s %s\n", $1,$2,$4,$6'} | grep -E "Evicted" |
while read line; do ns=$(echo $line | cut -d , -f 1); pod=$(echo $line | cut -d , -f 2); age=$(echo $line | cut -d, -f 6) ;
final_age=$(awk -F "d" '{print (NF > 1) ? $1 : 0}' <<< "$age");
if [[ $final_age -gt 30 ]]; then kubectl delete pod --dry-run='server' -n "$ns" "$pod"; fi done
The intention is to fetch the old evicted pods which their age is greater than 30 days and delete them .. can you please check as it returns null on my machine..
expected output: the names of pods which will be deleted
resulted output: null