The Wanderer wrote:
IOW: Having the "cut out any lines that mention the command that got the search pattern passed to it" command come last is likely to be a necessity.
thanks. so i have changed it back again for the last grep.
#!/bin/bash
port=$1
if [ -z "$port" ];then
echo "usage: $0 port" >&2
exit 1
fi
ps=$(lsof -i :"$port" |awk '/LISTEN/ {print $2}')
if [ -z "$ps" ];then
echo "no this port, or I don't have privilege to list the port" >&2
exit 1
fi
ps -efw |grep "$ps" |grep -v grep
exit 0