1827439 Members
6566 Online
109965 Solutions
New Discussion

Re: Unix Command needed

 
Bokoko
Advisor

Unix Command needed

I'm willing to use the "ps" command in order to detect a used/locked file in a specific directory but this command shows/displays me the similar files used by some processes. Would you please assist me in this case.

I've used this command:

$ ps -aef | grep PAYXTR.LIS
===============================================
ebokoko 21248 21232 0 10:22:15 pts/tk 0:00 vi /consult/6/runs/users/S.O./PAYXTR.LIS

con6 21156 20746 0 10:18:04 pts/tf 0:00 vi /consult/6/users/S.O./PAYXTR.LIS

root 21227 21192 0 10:20:53 pts/tj 0:00 vi PAYXTR.LIS
===============================================

Thanks.

E.Armand-Blaise
12 REPLIES 12
Tom Geudens
Honored Contributor

Re: Unix Command needed

Hi,
Are you perhaps looking for "fuser -cu" ?
Check "man fuser".

Regards,
Tom
A life ? Cool ! Where can I download one of those from ?
Armin Feller
Honored Contributor

Re: Unix Command needed

Hi,

perhaps the LSOF utility will help:

$ lsof +aL1 /usr

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
tail 2790 root 0r VREG 64,0x4 13394720 97 /home (/dev/vg00/lvol4)

You can download it by:
http://hpux.asknet.de/hppd/hpux/Sysadmin/lsof-4.64/

Or perhaps the FUSER command helps also?! ;-)

Please try it.

Best regards,
Armin
Vicente Sanchez_3
Respected Contributor

Re: Unix Command needed

Hi,

You can use fuser -u file_name. This shows the users and pids that have access to the file/directory.

HTH, Vicente.
Robin Wakefield
Honored Contributor

Re: Unix Command needed

Hi,

Try using fuser to list processes that have the file open, e.g.

# fuser /var/adm/syslog/syslog.log
/var/adm/syslog/syslog.log: 410o

# ps -fp 410
UID PID PPID C STIME TTY TIME COMMAND
root 410 1 0 Nov 24 ? 0:01 /usr/sbin/syslogd -D
#

Rgds, Robin
T G Manikandan
Honored Contributor

Re: Unix Command needed

you can determine what files the process has open using lsof

check the lsof for 64 bit here

ftp://coast.cs.purdue.edu/pub/tools/unix/sysutils/lsof/binaries/hpux/

Thanks
Bokoko
Advisor

Re: Unix Command needed

Thank you for your reply.

The preview command "fuser" is looking for a file system mounted on this file "PAYXTR.LIS". However, how to know exactly that a file is locked by a user (file in a specific directory).?
Bokoko
Advisor

Re: Unix Command needed

I,m still busy to test the "fuser" command and the "ps -fp" one.

For the utility, I can't use it because I'm running the B.11.00 32 bits.

Many thanks.
Armin Feller
Honored Contributor

Re: Unix Command needed

Hi,

if you are looking vor 'lsof', please go to following URL:

http://hpux.asknet.de

and search for 'lsof', I'm sure you will find a version for HPUX 11.00 (32bit).

Regards,
Armin
T G Manikandan
Honored Contributor

Re: Unix Command needed

Bokoko
Advisor

Re: Unix Command needed

I wrote named "BISLOCK". The purpose is to check if the PAYXTR.LIS file is opened by another User (file in the current directory : /consult/6/users/S.O. )

I'd like to combine the both commands "fuser" and "ps -pf" . would you assist me. This is the contain of the script "BISLOCK" which receives two parameters :

$1 = /consult/6/users/S.O.
$2 = PAYXTR.LIS

==============================================
i=0
directory=$1;export directory
payxtract=$2;export payxtract
files=`echo $directory"/"$payxtract`;export files

LOOP=y; export LOOP
#
while [ $LOOP = y ]
do
# -- Verify that $2 is not locked
by an Online User --

i=`ps -aef |grep $files|wc -l`

# if the return value is not 0 then
the file is in use.

if [[ $i != 0 ]]
then
{echo ERROR CYBMON Problem
Accessing File $2
sleep 20
}
else
LOOP=n; export LOOP
break
fi
#
done
#
H.Merijn Brand (procura
Honored Contributor

Re: Unix Command needed

As already said, fuser -c should be your base. Use it from a mount point, and it'll show all processes that use any file on the mounted file system.

lsof is the perfect tool - no, realy - to dig into problems you face. Both fuser and ps do not offer enough interface options to get to the bones. lsof does. Learn to use lsof. Install it yesterday.
Enjoy, Have FUN! H.Merijn
Darrell Allen
Honored Contributor

Re: Unix Command needed

Hi,

If you want to see the busy files in a directory:
cd /directory
fuser * .??*

lsof is much more functional and returns more information than fuser however fuser works fine for simple checks.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)