I want to kill a process in specified port (variable)
export PORT=3030
netstat -ntlp | awk '$4~/:*${PORT}$/{gsub(/\/.*/,"",$NF);cmd="kill -9 "$NF;system(cmd)}'
but variable PORT doesn't get in the command.
bashcommand-line-interfacelinux
I want to kill a process in specified port (variable)
export PORT=3030
netstat -ntlp | awk '$4~/:*${PORT}$/{gsub(/\/.*/,"",$NF);cmd="kill -9 "$NF;system(cmd)}'
but variable PORT doesn't get in the command.
Best Answer
use lsof for this task: