2

I have a process that can have multiple instances. ps shows the instance name, whereas netstat of course gives the name of the binary instead of the instance name. My goal is to use something like

ps -ef | grep Actimize_CDD | grep -v "grep" | awk '{print $2}'

as input to grep on netstat, something like:

netstat -anp | grep tcp | grep LISTEN | grep $resultFromPrevious | awk '{print substr($4, length($4)-3,length($0))}'

I've been looking at xargs and tried a few command substitutions, but of course instead of grepping for the string it tries to execute grep on the input string.

Thoughts? I'd like to stick with what I know (awk, piping, xargs) if possible, although I'm open to learning new things.

2
  • you can use backticks ( ` ) to get the result of a command... so if both your commands work for themselves that should do the trick. If not: more tinkering required.
    – der bender
    Apr 24, 2020 at 19:24
  • you should state here (and focus on) your goal, not focus too much on the method you are attempting to use to reach it. If the goal is to list Ip infos about processes, try here: lsof -Pn | grep "Actimize_CDD" and grep further on the ip infos you seek Apr 24, 2020 at 23:19

1 Answer 1

0

I swear that I tried backtick, but der Bender is correct:

[root@puflopactmzaa01 External_File_System]# netstat -anp | grep tcp | grep LISTEN | grep ps -ef | grep Actimize_CDD | grep -v "grep" | awk '{print $2}' | awk '{print substr($4, length($4)-3,length($0))}'

yields the output:

2355 2356 2357 2358

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .