下面是所有正在运行的 httpd 进程的进程转储。
$ ps -ef | grep '[b]in/httpd'
wsadmin 8465 8463 0 Jul 13 ? 1:21 /web/apps/perf/apache/2.4.52/https-model/bin/httpd -k start
wsadmin 23234 18662 0 14:00:34 ? 0:01 /web/apps/perf/apache/2.4.52/https-perf/bin/httpd -k start
wsadmin 14098 6780 0 Jul 20 ? 1:07 /web/apps/perf/apache/2.4.52/https-msp/bin/httpd -k start
wsadmin 28824 18662 0 11:31:13 ? 0:03 /web/apps/perf/apache/2.4.52/https-perf.web/bin/httpd -k start
wsadmin 7380 18662 0 09:30:35 ? 0:03 /web/apps/perf/apache/2.4.52/https-perf.myapp/bin/httpd -k start
我希望获得每个的主目录,例如
/web/apps/perf/apache/2.4.52/https-perf.myapp
。
我尝试过
ps -ef | grep '[b]in/httpd' | awk '{print $8}'
,但就像你看到的那样,主目录并不总是第8列。
因此,我需要一个适用于 linux 和 solaris 的解决方案。
这应该会得到预期的结果:
ps -ef | grep -Po '.* \K(.*)(?=/[b]in/httpd)'
我没有 Solaris 系统可供测试。