0
#!/bin/bash
#fauz-pas
num=1
bool=0
while [ "$bool" -eq 0 ]
do
ps aux | grep "$1" | grep -v "color" | grep -v "grep" > isahawk
crazy="$(awk -F" " '{print $2}' isahawk)"
echo x"$crazy"x
kill $crazy 2> error
if [ "$crazy" = "" ]
then
echo ":_ $crazy: No such process"
bool=1
echo "ha,finally"
fi
sleep 1
done
- This is a script to kill a process
- I expect to get a single pid as an output but rather i get a list
Output
:~$ ./kil\ vlc vlc
x17311
17363
17561
17794
18033
18139
18278
18335
18337
18371
18452
19196
19199
19213
19230
19262
19326
19354
19369
19380
19389
19409
19925
19936x
Terminated
Output of ps aux | grep "vlc"
ubuntu 20127 4.5 1.5 868204 59788 ? Sl 14:24 0:00 /usr/bin/vlc --started-from-file
ubuntu 20139 0.0 0.0 14224 1012 pts/2 S+ 14:24 0:00 grep --color=auto vlc
Output of pgrep vlc
20127
1Have you tried looking at the full ps output that you're processing (before cutting off the PID)? The other fields might tell you what the extra processes belong to, and whether they're false positives. Also – have you considered using
pgrep
? – user1686 – 2019-03-15T08:52:05.253If they are indeed false positives?? Why are they showing up ? – Passerby – 2019-03-15T09:08:03.243
1Because that's the definition of a false positive? Something that matches your criteria while you don't intend it to match. Looking at your output you should already realize that your grep and awk are not working as intended. – Seth – 2019-03-15T09:16:50.333
1Why such a rube-goldburg solution to kill a process/list of processes? Your grep command is finding unrelated processes, and you can look at the isahawk file to see what it found because you are not cleaning up after yourself. – davidgo – 2019-03-15T19:00:48.543
The above comment is right, you should examine
isahawk
. Nobody noticed you had named the script "kil vlc
". It detects and terminates itself (thereforeTerminated
), regardless of whethervlc
is running or not. Everything afterkill $crazy
is futile. – Kamil Maciorowski – 2019-03-27T20:19:36.417