Unix Shell - test if file is open

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2006 > test if file is open





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author test if file is open
James

2005-11-10, 6:03 pm

Is there a way to test in a bourne/bash shell script
whether a file is opened by other programs?

If not, a C program may help also.

Thanks in advance.
James

Janis Papanagnou

2005-11-10, 6:03 pm

James wrote:
> Is there a way to test in a bourne/bash shell script
> whether a file is opened by other programs?
>
> If not, a C program may help also.
>
> Thanks in advance.
> James
>


man lsof


Janis
RolandRB

2005-11-11, 7:49 am


James wrote:
> Is there a way to test in a bourne/bash shell script
> whether a file is opened by other programs?
>
> If not, a C program may help also.
>
> Thanks in advance.
> James


Use

/usr/sbin/fuser -u

RolandRB

2005-11-11, 7:49 am


James wrote:
> Is there a way to test in a bourne/bash shell script
> whether a file is opened by other programs?
>
> If not, a C program may help also.
>
> Thanks in advance.
> James


Use

/usr/sbin/fuser -u

RolandRB

2005-11-11, 7:49 am


James wrote:
> Is there a way to test in a bourne/bash shell script
> whether a file is opened by other programs?
>
> If not, a C program may help also.
>
> Thanks in advance.
> James


Use

/usr/sbin/fuser -u

johnsonbryce

2006-03-10, 5:57 pm

I need to write a function that will work in sh/ksh shell that will
test to see if a file has already been opened for writing by another
user, but i don't have execute permissions on fuser and lsof not on
system

i think you can also do it using the "test
-t" but can't seem to figure out the syntax - has
anyone done this?

Keith Thompson

2006-03-10, 8:47 pm

bryce.johnson@ingenix-dot-com.no-spam.invalid (johnsonbryce) writes:
> I need to write a function that will work in sh/ksh shell that will
> test to see if a file has already been opened for writing by another
> user, but i don't have execute permissions on fuser and lsof not on
> system
>
> i think you can also do it using the "test
> -t" but can't seem to figure out the syntax - has
> anyone done this?


No, "test -t" does something different (it tests whether a given file
descriptor (not named file) is opened on a terminal).

If you don't have permissions to run fuser or lsof, you probably can't
do this (if I'm mistaken, I'm sure someone will say so). This is
information about other users that the system deliberately doesn't let
you have. It's possible to install the fuser command SUID root (if
you have root access already), but doing so might open security holes.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com