I want to get pid of a process and then kill it. When I do ps -ef | grep "python3 bot.py"
I have this output:
root 43903 1 0 Jun26 ? 00:03:28 python3 bot.py
root 48808 48298 0 17:57 pts/0 00:00:00 grep --color=auto python3 bot.py
and I want to get the PID 43903
. How can I accomplish this using bash script?
So far I have written:
ps -ef | grep "python3 bot.py" | awk "NR==1 {print $1}"
which outputs
root 43903 1 0 Jun26 ? 00:03:28 python3 bot.py
But now when I rerun awk on it, it has no output. How can I get the 43903
from this line?bash