fuser trickiness

I encountered this one a bit over a year ago while having a conversation with Ed in MPK (or is it a year and a half?). The fuser command is used to list the processes using a file system - fuser /home/bubba would list all the users of /home/bubba; and you can kill them too, using the -k option. So far so good.
What happens, though when you want to do something with the output?
haiiro[64i]~% fuser /home/bubba
/home/bubba:     6780c    6760c    6758c    6756c    6502c    6422c    6404c   6368c    6332c
6331c    6330c    6322c    6308c    6301c    6206c    6081c    5951c    5879c    5756c    5251c
5247c    5201c    5092c    5004c    4992c    4987c    4985c    4982c    4980c    4968c    4952c
4920c    4672c    4080c    4079c    3990c    3989c    3987c    3985c    3983c    3981c    3979c
3975c    3973c    3969c    3963c    3943c    3939c    3937c    3935c    3898c    3896c    3893c
3891c    3882c    3880c    3836c    3834c    3831c    3769c    3726c
it's a bit hard to parse? not so! What you can do is redirect stderr to /dev/null and magic happens
haiiro[64i]~% fuser /home/bubba 2>/dev/null
6781    6760    6758    6756    6502    6422    6404    6368    6332    6331    6330
6322    6308    6301    6206    6081    5951    5879    5756    5251    5247    5201
5092    5004    4992    4987    4985    4982    4980    4968    4952    4920    4672
4080    4079    3990    3989    3987    3985    3983    3981    3979    3975    3973
3969    3963    3943    3939    3937    3935    3898    3896    3893    3891    3882
3880    3836    3834    3831    3769
No parse issues there. Then you can get full process information on each of the processes using a small bit of shell:
haiiro[64i]~% ps -o pid,args -p "$(fuser /home/bubba 2>/dev/null)"
  PID COMMAND
 6206 /usr/openwin/bin/xterm -geom 80x25 -e /bin/zsh
 3943 /usr/lib/evolution/1.4/evolution-alarm-notify --sm-config-prefix /evolution-ala
 3939 nautilus --sm-config-prefix /nautilus-udaGgf/ --sm-client-id 11819cee2200010909
 3935 metacity --sm-save-file 1106677632-2610-3195804027.ms
 3880 /bin/ksh /usr/dt/config/Xsession2.jds
 3834 /usr/dt/bin/sdt_shell -c      unset DT;     DISPLAY=:0;       /usr/dt/bin/dt
:
:
:
Just what the doctor ordered for a sysadmin.
Comments:

Whats perhaps worrying is that you want to have a user called bubba on your system.

Posted by SMG on January 27, 2005 at 05:09 AM GMT #

Post a Comment:
Comments are closed for this entry.
About

petesh

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today