Try to extract the process ID that is using a given port number from the fuser output as below
$ fuser 9092/tcp
9092/tcp: 5920
Extracting the PID using awk is not happening
$ fuser 9092/tcp | awk -F: '{print $2}'
9092/tcp:
from the extracted PID, I want to do ls -l /proc/5920/exe
like
ls -l /proc/$(fuser 9092/tcp | awk -F: '{print $2}')/exe
Versions of the binary as below:
bash --version # GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
fuser --version # fuser (PSmisc) 22.20
The informal part of the output from
fuser
goes to standard error. The output to standard output is already computer-readable. (This is a feature, not a bug.)Trivially, you can redirect standard error to get rid of the stderr output if you think it's useless or distracting.
You can easily establish this for yourself by piping e.g. to
nl
Notice how the
9092/tcp:
output does not get a line number -- it's not being piped tonl
.So your actual code could look like
(though usually don't use
ls
in scripts.