Open files by users?

Michael Bruck mike at mipos3.UUCP
Sat Aug 16 17:13:35 AEST 1986


I earlier asked:

> How can one tell which users have what files open?  I essentially need
> to see if a particular file is open and by whom. 

Thanks to everyone on the net who responded.  As I found out, on system V,
there's a program called fuser which does what I want.  Unfortunately,
I'm using Ultrix (a.k.a. BSD 4.2~3) so following a suggestion by someone
about using pstat -i to get the UID's of all the files open, I came up 
with the following quick and dirty shell that does the job.  It's kind
of slow and cumbersome but it saved me from writing a new program and 
it works well enough for my needs.  It's short enough not to bother with
net.sources.

-------------------------------------------------------------------------
#!/bin/csh
set noglob
set com = $0
if ($#argv == 0) then
    echo2 "Usage:  $com:t file"
    exit 1
endif

foreach ifile ($argv[*])
	if ( ! -f $ifile ) then
		echo $ifile not found
		exit 1
	endif
	set inode=`ls -i $ifile`
	set user=`pstat -i | grep $inode[1] | awk -F, '{print $2}'`
	if ( "$user" != "" ) then
		set name=`grep $user[7] /etc/passwd | awk -F: '{print $1}'`
		echo $name has $ifile open
	else
		echo $ifile not open
	endif
end
-------------------------------------------------------------------------

	--Michael Bruck
	  Intel CAD, Santa Clara, CA
	  {decwrl,hplabs,amdcad}!intelca!mipos3!mike



More information about the Comp.unix.wizards mailing list