Which filesystem a command is executing from?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Which filesystem a command is executing from?
# 1  
Old 02-22-2011
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.
# 2  
Old 02-22-2011
If I understand your requirement, maybe this:
Code:
 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:
Code:
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.
This User Gave Thanks to Perderabo For This Post:
# 3  
Old 02-22-2011
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?
# 4  
Old 02-22-2011
I continue to believe that my line of code is what you want. If not, I must not understand what you need. Smilie But -9s is a right-justified field 9 characters in length for a string.

Last edited by Perderabo; 02-22-2011 at 03:12 PM..
# 5  
Old 02-22-2011
Think he just wants the filesystem any kuxagent processes are running from eg:

Code:
/opt
/opt/clus2/IBM
/opt/IBM/ITM

This should get it done:

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

This User Gave Thanks to Chubler_XL For This Post:
# 6  
Old 02-23-2011
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.

Code:
 
$ 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.
Code:
 
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.
# 7  
Old 02-23-2011
Try:

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


Last edited by clx; 02-23-2011 at 08:46 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Command to check on which vg filesystem resides

Hi, I need to know on which volume group filesystem resides. TIA (5 Replies)
Discussion started by: sumanthupar
5 Replies

2. Shell Programming and Scripting

Executing a command in subshell

Hi All, I am trying to create a shell script which runs on my linux machine. The requirement is so that, ade createview xyz -> this steps creates a view ade useview xyz -> we are entering inside the view ade begintrans -> begin a transaction My script has following code : lets say... (2 Replies)
Discussion started by: Dish
2 Replies

3. Solaris

Unix command to fill filesystem

I have been trying to fill all available file space on my Solaris box for my project but have not been successful. I have tried the following script: tr '\0' '\060' < /dev/zero | dd of=zero2.txt bs=1024 count=1953125 But the only thing i get in return is this: "d: bad numeric argument:... (8 Replies)
Discussion started by: rbur101
8 Replies

4. UNIX for Dummies Questions & Answers

executing a command using ssh

Hi All, I am trying to execute a command using ssh as below. ssh user123@servername "which ctmcontb" It is gving the error as below no ctmcontb in /usr/bin /usr/sbin /opt/sysadm/bin Not sure from where the PATH is getting picked up. But When I login direclty to the server I am... (5 Replies)
Discussion started by: anilreddy103
5 Replies

5. AIX

Command executing to be in the background !

Guys I'm working to make in AIX script and I have some commands need to be excited by that script Like the below commands ... startsrc -s sshd I want that executing to be in the background of the system I do not like to see the out put of that (3 Replies)
Discussion started by: Mr.AIX
3 Replies

6. Shell Programming and Scripting

executing command from subdirectories

Hello, I've been trying to run 'ls -1R | wc -l' inside of sub directories to in order to determine how big each folder is. find . -maxdepth 1 -type d | while read folder do cd "$folder" && echo "$folder has $(ls -1R | wc -l) files" && cd .. done or for... (3 Replies)
Discussion started by: NoobProgrammer
3 Replies

7. Solaris

what command was used to create a filesystem

How do we determine what command was used (either newfs or mkfs) to create a filesystem? Thanks, (2 Replies)
Discussion started by: Pouchie1
2 Replies

8. Shell Programming and Scripting

Executing a command at startup

Hey all, How do I execute a file at startup automatically. From what I've read is that I need to put it into my .bashrc file. I'm not sure where to go from there. Can I just type commands into that and they'll run next time I restart my server? Right now I have added these lines: cd... (2 Replies)
Discussion started by: NathanWarden
2 Replies

9. UNIX for Dummies Questions & Answers

Executing a unix command

Hi, I need to execute the following unix command through my java code - zip -e When i execute this command from the command prompt, i am prompted for a password in the following manner - Enter password: Verify password: Is it possible to provide the password inthe first command itself... (5 Replies)
Discussion started by: jacob23
5 Replies

10. Solaris

What is the command to increase filesystem on solaris

I wanted to know what is the process or command to increase a filesystem on solaris. For example the /tmp directory. (3 Replies)
Discussion started by: strikelit
3 Replies
Login or Register to Ask a Question