1

I'm trying to finish up a maintenance script, and I'm getting caught up with the following line:

PUID=$(ps aux | grep $PID | grep -v $USER| cut -d' ' -f1)

I'm trying to pull a specific process ID ($PID) out of the ps aux command, (while ignoring the process the user just created with the same PID), then eliminate all but the user name of the process owner.

Currently, the command runs fine when run in the command line, however I've been having issues assigning it to the variable $PUID, or even just executing it as a command. Any advice?

EDIT:

I'm trying to get this figured out and I believe there is still a problem in passing the variable $PID, right now it's pulling from a file (which it does properly) using this line

PID=$(cat /nfs/pdx/home/komcconx/PID/current/pid)

and if I add an echo $PID it returns the proper pid.

when I run the command PUID=$(ps -p $PID -o uname=), I get an error saying "ERROR: Process ID list syntax error." and if I runn the command with a "1" in the place of $PID it properly returns "root"

any ideas?'

Final edit:

Found out the issue was the PID was being pulled from a DOS file, and I was trying to run the command with a DOS newline, this issue is closed!

1
  • Oh woops, I had that in there as I was trying to focus on getting at least the first grep to work, edited. Commented Dec 8, 2014 at 21:15

1 Answer 1

2

If you only want the user name of a process you can use -o option:

PUID=$(ps -p $PID -o uname=);
echo $PUID
Sign up to request clarification or add additional context in comments.

8 Comments

Option handling varies greatly between different versions of ps; consult your local man page for the correct syntax on your machine.
Do not use old and outdated back-tics, use parentheses like this: PUID=$(ps -p $PID -o uname=) (also ; at end is not needed)
Hey guys, I'm trying to get this figured out and I believe there is still a problem in passing the variable $PID, right now it's pulling from a file (which it does properly) using this line
Hey guys, I'm trying to get this figured out and I believe there is still a problem in passing the variable $PID, right now it's pulling from a file (which it does properly) using this line PID=$(cat /nfs/pdx/home/komcconx/PID/current/pid) and if I add an echo $PID it returns the proper pid. when I run the command PUID=$(ps -p $PID -o uname=), I get an error saying "ERROR: Process ID list syntax error." and if I runn the command with a "1" in the place of $PID it properly returns "root" any ideas?
@dustyblade print the content inside the file: nfs/pdx/home/komcconx/PID/current/pid in the post.
|

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.