Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i

Status
Not open for further replies.

ediforu

IS-IT--Management
Oct 4, 2002
8
US
how do i check if a file is being written to? and/or
wait for it to finish writing, before i perform further
processing?

thanks in advance
 
can't find this command on our system, is there
any other way?

Thanks
 
Just put a condition check in your script. For instance if you have the following:

#!/usr/bin/ksh -p

DIR=/test/test
FILE=${DIR}/needsomeinfo

/usr/bin/grep "SOMEWORDHERE" ${FILE} >> /tmp/NEWFILE

if [ ! -s /tmp/NEWFILE ]
then
print "Command: grep failed to get any output from FILE: ${FILE}, this file did not contain the word you were looking for, please try again!!"
else
print "Command: grep finished successfully."
fi


That is an example of what I think you want.
 
If on solaris, the standard distribution should have fuser [as jamisar has mentioned].

If on other OS, try to get 'lsof'

NAME
lsof - list open files

DESCRIPTION
Lsof revision 4.50 lists information about files opened by
processes for the following UNIX dialects:

AIX 4.1.[45], 4.2[.1], and 4.3[.123]
BSDI BSD/OS 2.1, 3.[01], and 4.[01] for Intel-based systems
DC/OSx 1.1 for Pyramid systems
DEC OSF/1, Digital UNIX, Tru64 UNIX 2.0, 3.2, 4.0, and 5.0
FreeBSD 2.1.[67], 2.2[.x], 3.[012345], 4.0, and 5.0 for Intel-
based systems
HP-UX 9.01, 10.20, and 11.00
Linux 2.0.3[2346], 2.1.x, and 2.2.x for Intel-based systems
NetBSD 1.[2345] for Alpha, Intel, and SPARC-based systems
NEXTSTEP 3.[13] for NEXTSTEP architectures
OpenBSD 2.[01234567] for Intel-based systems
OpenStep 4.x
Reliant UNIX 5.4[34] for Pyramid systems
SCO OpenServer Release 3.0 and 5.0.[0245] for Intel-based
systems
SCO UnixWare 2.1.[123] and 7[[.0].1] for Intel-based systems
Sequent PTX 2.1.9, 4.2.[13], 4.[34], 4.4[.1246], and 4.5[.1]
for Sequent systems
Solaris 2.5.1, 2.6, 7, 8 BETA, and 8 BETA-Refresh
SunOS 4.1.x
Ultrix 4.2

DISTRIBUTION
The latest distribution of lsof is available via anonymous
ftp from the host vic.cc.purdue.edu. You'll find the lsof
distribution in the pub/tools/unix/lsof directory.

Lsof is also mirrored elsewhere. When you access
vic.cc.purdue.edu and change to its pub/tools/unix/lsof
directory, you'll be given a list of some mirror sites. The
pub/tools/unix/lsof directory also contains a more complete
list in its mirrors file. Use mirrors with caution - not
all mirrors always have the latest lsof revision.

Some pre-compiled Lsof executables are available on
vic.cc.purdue.edu, but their use is discouraged - it's
better that you build your own from the sources. If you
feel you must use a pre-compiled executable, please read the
cautions that appear in the README files of the
pub/tools/unix/lsof/binaries subdirectories and in the 00*
files of the distribution.

vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Thanks for your input, ALL.
I stumbled onto something that worked perfectly for me.

It is a simple scenario where I have to concatenate files from a specific production directory. I can't do a &quot;cat * > catfl&quot; because the production job could be writing to the directory at the same time, so I needed some kind of a check.
This is what I came up with using cksum where if the file is still being written to then cksum waits till that completes, and is working great. let me know if you see any issues with this.

#!/bin/ksh

if (( $(ls mb | wc -l) < 1 )); then
exit
fi

set `ls mb`

for i in $*
do

cksum mb/$i 1>/dev/null
if [ $? != 0 ]; then
print &quot;Error getting cksum on $i&quot;
exit
fi
cat mb/$i >> toca
if [ $? == 0 ]; then
rm mb/$i
else
print &quot; Error concatenating $i: $(date '+%m/%d/%y %H:%M:%S')&quot;
fi

done

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top