Which filesystem a command is executing from?

Hi. We can have one or more agents of a particular type running on our AIX and Solaris servers. As these agents have usually been installed into their own filesystems, I need to capture the filesystem names for auditing purposes. I've had a search through the forums can see something that fits the bill. I can grep for the process name (kuxagent) which will return the paths and user names the process is running as, but I'm having trouble combining them all on a one-liner command. Is there a way to pipe the grep into a df maybe?

User: itmuser /opt/IBM/ITM/bin/kuxagent
User: itmclus /opt/clus2/IBM/ITM/bin/kuxagent

Thank you.

If I understand your requirement, maybe this:

 ps -o 'user,args' -e | awk '{ printf "user: %-9s %s \n",$1,$2 }'

I tested it on Solaris and here is an excerpt of the output:

user: root      /usr/sfw/sbin/snmpd
user: postgres  /opt/orb/postgresql-8.2/bin/postgres
user: postgres  /opt/orb/postgresql-8.2/bin/postgres

Normally on Solaris we use nawk, but this is so simple it works with even the antique awk. You still need to grep what you want.

Hi Perderabo. Thanks for your prompt reply. I'm really just looking for any of the filesystem names used by a particular process called kuxagent. So what I'm trying to do is find how many processes called kuxagent are running, capture the name of the user each process is running as, and then try and identify a filesystem name they're running from out of the results. Can I also ask what %-9s does?

I continue to believe that my line of code is what you want. If not, I must not understand what you need. :confused: But -9s is a right-justified field 9 characters in length for a string.

Think he just wants the filesystem any kuxagent processes are running from eg:

/opt
/opt/clus2/IBM
/opt/IBM/ITM

This should get it done:

ps -o args -e | grep kuxagent | while read cmd args
do
    df $cmd | nawk 'NR==2 {print $NF}'
done | sort | uniq

Thanks Chubler_XL. I tried your version on Solaris but got the message:

df: (grep ) not a block device, directory or mounted resource

I need to have the command in a one-liner, unfortunately, as getting scripts copied to the servers is difficult but we can run commands on them and capture the output.

 
$ ps -o 'user,args' -e | awk '{ printf "user: %-9s %s \n",$1,$2 }'|grep kuxagent
 
user: itmuser /opt/IBM/ITM/bin/kuxagent
user: itmclus /opt/clus2/IBM/ITM/bin/kuxagent

Is it possible to have the 'user' value piped into a df ~user on the same line after the grep so that it displays the filesystem in one go?

e.g.

 
ps -o 'user,args' -e | awk '{ printf "user: %-9s %s \n",$1,$2 }'|grep netman|df ~$1

This isn't working, but hopefully it explains (however badly!) what I'm trying to do.

Thanks for your efforts so far.

Try:

ps -o 'user,args' -e | awk '/kuxagent/ {print "~"$1}' | df

Hi there. Tried that on SunOS and AIX and it just returns an unfiltered df listing I'm afraid.

I edited my post may be you should search with 'kuxagen' ?

ps -o 'user,args' -e | awk '/kuxagent/ {print "~"$1}'

First see the output then try piping df.

My mistake for using the wrong process name in my earlier example.

On Solaris, that command shows the 2 userids running kuxagent, as well as my own userid which is searching for the kuxagent process.

$ ps -o 'user,args' -e | awk '/kuxagent/ {print "~"$1}'
~itmuser
~asoames
~itmclus
$ ps -o 'user,args' -e | awk '/kuxagent/ {print "~"$1}' |df

Piping it into df just shows a full df listing with no filtering?

Means it is evaluating the "df" command right?
what filtering you you require? I guess only file system?
Can you show the output of the above command? I am having HP-UX and df output is varies in linux

$ ps -o 'user,args' -e | awk '/kuxagent/ {print "~"$1}' | df
/                  (/dev/md/dsk/d10   ):10087646 blocks   924064 files
/proc              (/proc             ):       0 blocks    29672 files
/etc/mnttab        (mnttab            ):       0 blocks        0 files
/dev/fd            (fd                ):       0 blocks        0 files
/var               (/dev/md/dsk/d30   ):13831854 blocks  1193823 files
/var/run           (swap              ):29657248 blocks   798312 files
/dev/vx/dmp        (dmpfs             ):29657248 blocks   798312 files
/dev/vx/rdmp       (dmpfs             ):29657248 blocks   798312 files
/tmp               (swap              ):29657248 blocks   798312 files
/home              (/dev/vx/dsk/rootdg/home):  973214 blocks   121649 files
/opt/IBM/ITM              (/dev/vx/dsk/rootdg/ITM): 2061956 blocks   257742 files
/opt/clus2/IBM/ITM       (/dev/vx/dsk/clusdg/ITM): 2063702 blocks   257960 files

...

So what I'm trying to have it display is just the filesystems that contain a running kuxagent process, if that's possible, or maybe I'm not explaining myself too well. Thanks.

So you want to get the first column from the above?

ps -o 'user,args' -e | awk '/kuxagent/ {print "~"$1}' | df | awk "{print $1}'

Almost. The one-liner commands needs to do this, in order.

  1. Are there any kuxagent processes running?
  2. Capture the userid that is running each kuxagent process
  3. Do a 'df ~userid' command for each userid returned. e.g. df ~itmuser df ~itmclus
  4. Which should return the results similar to below.
/opt/IBM/ITM              (/dev/vx/dsk/rootdg/ITM): 2061956 blocks   257742 files
/opt/clus2/IBM/ITM       (/dev/vx/dsk/clusdg/ITM): 2063702 blocks   257960 file
eval df $(ps -o 'user,args' -e | awk '/kuxagent/ {print "~"$1}')

Perfect! Thank you very much for your time and patience.

Withdrawn