I am trying to join output from ps and pwdx command. Can anyone point out the mistake in my command.
ps -eo %p,%c,%u,%a --no-headers | awk -F',' '{ for(i=1;i<=NF;i++) {printf $i",
"} ; printf pwdx $1; printf "\n" }'
I expect the last column in each row to be the process directory. But it just shows the value of $1 instead of the command output pwdx $1
This is my output sample (1 row):
163957, processA , userA , /bin/processA -args, 163957
I expected
163957, processA , userA , /bin/processA -args, /app/processA
Can anyone point out what I may be missing
Simplifying your example to focus on how to execute the
pwdx
command withinawk
and capture the result of this command into anawk
variable as this is where you were having issues:produces:
Try this:
Explanation:
awk '{print pwdx $1}'
will concatenate the awk variablepwdx
(which is empty) and$1
(pid). So, effectively, you were getting only thepid
at the output.In order to run a command and gets its output, you need to use this
awk
construct: