/ / bash script para kill PID de pgrep grunt - linux, bash, shell

script bash para matar PID de pgrep grunt - linux, bash, shell

Soy un noob allstar para golpear scripts. Mi script se parece a esto:

#!/bin/bash

pgrep grunt > target.txt
for i in target.txt
do kill $i
echo "killed $i"
done

Ahora, obviamente no funcionó y no sé cómo hacerlo funcionar. Quiero que este script para echo la salida de pgrep grunt al archivo target.txt y desde allí leer el PID y matar a esos procesos.

Respuestas

1 para la respuesta № 1

Para responder tu pregunta:

#!/bin/bash

while read i; do
kill $i
echo "killed $i"
done< <(pgrep grunt)

No se necesita un archivo externo.

Pero, ¿eres consciente de pkill existencia ?

 pkill grunt

pgrep, pkill: busque o señale procesos basados ​​en el nombre y otros atributos


0 para la respuesta № 2

Leer el archivo usando el script bash

#!/bin/bash
while IFS="" read -r line || [[ -n "$line" ]];
do
kill $line
echo "killed $line"
done < target.txt

0 para la respuesta № 3
#!/bin/bash

for pid in $(grep grunt) ; do
kill ${pid} && echo "killed ${pid}"
done