shell提取当前sshd的端口号和进程id


root权限下使用:
netstat -tnp | grep sshd
输出:
tcp 0 0 192.201.0.8:22 192.201.0.90:4614 ESTABLISHED 3604/sshd: yang [pr

如何对该字串用sed处理,使输出结果为:
sshd Port&&pid: 22 5412

sed shell

wakaka 10 years, 5 months ago

解决方案:
1.

   
  $ sudo netstat -anp | grep "sshd" | grep -v "\]" | sed -r 's/.*:([0-9]+).* ([0-9]*)\/.*$/sshd Port\&\&pid: \1 \2/' | sort | uniq
 

参考链接:
http://rainbird.blog.51cto.com/211214...

Hagu answered 10 years, 5 months ago

Your Answer