1

Writing a script to retrieve various environment parameters back from a list of servers. My script returns no value when ran but the same command returns the desired value outside of a script.

I have tried using a couple of variations to retrieve the same data. One of the commands fails because of restrictions placed on the accounts I have access to. The second command works but only if executed in an elevated mode.

This fails with access denied (pwdx is restricted)

dzdo pgrep -f /some/path | xargs pwdx

This works outside of a script but returns no value within a script

dzdo /bin/readlink -e /proc/"$(pgrep -f /some/path)"/cwd

When using "bash -x" to execute my scriipt, I see the "readlink" code is blank.

Ideally, I would like to return the PID and path of the process running as the "pgrep" command does. I can work with the path alone as returned by the "readlink" version returns. The end goal is to gather the information from several servers for audit purposes. (version, etc.)

Am I using the wrong syntax for the "readlink" command? I'm fairly new to coding bash scripts so I appreciate any guidance to help understand when to to what if I'm using a command in a script vs command line.

1 Answer 1

2

If pwdx is the restricted program, you need to run that with dzdo, not pgrep.

pgrep -f /some/path | dzdo xargs pwdx
Sign up to request clarification or add additional context in comments.

2 Comments

Well, that may be a facepalm moment. Thank you, that is something I had not tried. Can you enlighten me as to why "dzdo /bin/readlink -e /proc/"$(pgrep -f /some/path)"/cwd" returns nothing for "$(pgrep -f /some/path)"?
I'm not sure, I can't think of a reason why pgrep would work differently in the command substitution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.