0

I want to delete a process from process list pod_de.csv file

Content of pod_de.csv file

NAME                                READY   STATUS    RESTARTS   AGE
FebwinterMind-897654db-knbbj    2/2     Running   0          46h
DecNightmarch-897654db-n6qhk    2/2     Running   0          6d10h
DecNightmarch-897654db-v2rgt    0/2     Evicted   0          6d10h
DecNightmarch-897654db-5sswn    0/2     Evicted   0          6d10h
DecNightmarch-897654db-hqntn    2/2     Running   0          6d10h
DecNightmarch-897654db-z42r8    2/2     Running   0          35h
DecNightmarch-765897654db-qgbpb     2/2     Running   0          5d14h
AugNightmarch-774bbfc656-96bs6   2/2     Running   0          6d10h
AugNightmarch-774bbfc656-qnnkt   2/2     Running   0          6d10h
FebwinterMind-765897654db-gk5vw      2/2     Running   0          6d13h
FebwinterMind-765897654db-vhk8p      2/2     Running   0          6d13h
ogfileprocess-5h9ih8934b7b-dpbvt      2/2     Running   0          15h
nedesignprocess-765897654db-rshps     2/2     Running   0          6d10h
nedesignprocess-765897654db-rzqf7     0/2     Evicted   0          6d10h
nedesignprocess-765897654db-sbhps     2/2     Running   0          10h
referencedata-765897654db-xlc82      2/2     Running   0          6d11h
clientmyql-58b7d9b687-f9225   2/2     Running   0          5d18h
clientmyql-58b7d9b687-tfmrl   2/2     Running   0          5d18h

I want to kill "ogfileprocess-5h9ih8934b7b-dpbvt" process

I implemented this

#!/bin/bash
pods=$(kubectl get pods > pod_de.csv)
echo "$pods"
Running_OG_process=$(awk '/ogfileprocess/{print $1}' pod_de.csv)
echo "Running Process:" $Running_OG_process
kubectl delete pod $Running_OG_process

But I am getting additional \r\r\ and due to this it is not killing that particular process

Running Process: ogfileprocess-5h9ih8934b7b-dpbvt
Error from server (NotFound): pods "ogfileprocess-5h9ih8934b7b-dpbvt\r\r" not found

Actual value getting from file is

ogfileprocess-5h9ih8934b7b-dpbvt\r\r

I want

ogfileprocess-5h9ih8934b7b-dpbvt

So that I can kill the process.

Can Someone help me on this, or can we do this in another way. Full code will be highly appreciated

Chanty
  • 3
  • 2
  • the delimiter in your CSV file is `,` Please confirm. Just got confused as spaces are given in the question. – Tajinder Jul 23 '19 at 00:54
  • Actually, After executing "kubectl get pods" I am getting the running process. Which I wrote into "pod_de.csv" file, And from their I am trying to fetch the required value. – Chanty Jul 23 '19 at 01:08
  • Possible duplicate of [Removing Carriage Returns in a column](https://stackoverflow.com/q/17564838/608639), [Remove carriage returns from CSV data value](https://stackoverflow.com/q/46607729/608639), [How do I remove carriage returns from the input file using Bash?](https://stackoverflow.com/q/33510838/608639), [Remove carriage return in Unix](https://stackoverflow.com/q/800030/608639) and friends. – jww Jul 23 '19 at 03:40

1 Answers1

2

You can just do this to delete pod with ogfileprocess in its name:

kubectl get pods | grep ogfileprocess | awk '{print $1}' | xargs kubectl delete pod
Vikram Hosakote
  • 3,528
  • 12
  • 23
  • When I am executing directly it is working. But when i am pasting in a file and executing that file then it is not working "error: the server doesn't have a resource type "pod\r" error: the server doesn't have a resource type "pod\r"" – Chanty Jul 23 '19 at 01:47
  • Looks like you're getting a carriage return (`\r`) in output, try removing it by referring https://stackoverflow.com/questions/800030/remove-carriage-return-in-unix or https://superuser.com/questions/489180/remove-r-from-echoing-out-in-bash-script. – Vikram Hosakote Jul 23 '19 at 02:23