1

I run SAS codes through bash.

So when I do a ps -u <user-id> ..(1) I get the following:

 UID PID TTY TIME CMD 327208 921620 - 0:00 sftp-server 327208 1409136 - 0:00 sshd 327208 1503426 pts/24 0:00 ps 327208 1683576 pts/24 0:00 elssrv 327208 2334914 pts/24 0:00 ksh 327208 2609352 pts/24 0:00 sas 327208 2838702 pts/24 0:04 sas 327208 3490018 pts/24 0:00 elssrv 327208 4436128 - 0:00 sftp-server 327208 4722852 pts/24 369:02 sas 327208 4964572 pts/24 0:00 elssrv 327208 5959866 - 0:01 sshd 327208 5976318 - 0:01 sshd 

Now, if I do ps -u <user-id>|grep sas ..(2)

I get the sas processes:

327208 2609352 pts/24 0:00 sas 327208 2838702 pts/24 0:05 sas 327208 4722852 pts/24 369:51 sas 

On the other hand if I do a ls -l /proc/4722852/cwd, ..(3) I get the location where I ran the process with PID 4722852.

Is there a way to connect the command in (2) and (3)?

The output would be the location of all SAS codes that I get by running ps -u <user-id>|grep sas?

3
  • You can use ls -l /proc/$(pgrep sss)/cwd and otherwise use ls -l /proc/$(pgrep sss | tail -n1)/cwd Commented Jun 28, 2017 at 13:02
  • My unix is controlled by company admin so I can't add xargs / pgrep to it. Is there a way to pipe the info from awk into the ls -l? For eg. something like: ps -u <userid> | grep sas | awk '{print $2}' | ls -l /proc/$@/cwd Commented Jun 29, 2017 at 8:35
  • I'm not sure what your final goal is. pgrep is accessible for normal users as well and not limited to root. If you want it quick and dirty ps -u <user-id> |awk '/sas/{print $1}' | ls -l /proc/$(</dev/stdin)/cwd Commented Jun 29, 2017 at 11:19

1 Answer 1

1

Yes, there is a very easy way to do so. There are actually many ways to get what you want, depending on how much information you want to come out. The first way I can think of:

ps -u <userid> | grep sas | awk '{print $2}' | xargs ls -l 

The first two commands do exactly what they do in your second command. The awk command prints out only the second item from each line (items separated by whitespace by default), the xargs command says "pass what you see on STDIN to the following command as parameters".

1
  • My unix is controlled by company admin so I can't add xargs / pgrep to it. Is there a way to pipe the info from awk into the ls -l? For eg. something like: ps -u <userid> | grep sas | awk '{print $2}' | ls -l /proc/$@/cwd Commented Jun 29, 2017 at 8:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.