The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
all tcp are CLOSED on SCO Unix on VMWARE martocapo SCO 5 03-26-2008 01:58 PM
Find out the maximum growing file in a mount raman1605 UNIX for Dummies Questions & Answers 3 10-01-2007 09:25 PM
.osm file growing golfs4us UNIX for Dummies Questions & Answers 1 07-23-2007 11:40 AM
how can i check if text file is closed ? umen Shell Programming and Scripting 13 01-12-2007 11:40 AM
file activity (open/closed) file descriptor info using KORN shell scripting Gary Dunn UNIX for Dummies Questions & Answers 3 06-07-2004 02:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-05-2005
kslakshm kslakshm is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 1
How to check a file in UNIX is closed or growing?

We have a third party tool in UNIX to kick off a 'file copy' job based on a file existance. If a specific file exists in an UNIX directory, another process should start copy the file into another system for further processing. The issue is, the copy job is starting as soon as the file exists in the directory but the file creation process is still writing records into the file.

How to identify the file is closed before starting the 'file copy' job.

We have a UNIX script to check the file size for every 30 seconds and compare the previous and current size, if no difference in size
we assume the file is closed. This approach does not work if the file creation process is delayed or slow due to network etc..

Any help is appriciated.

Thanks
K. Lakshmanan
  #2 (permalink)  
Old 01-05-2005
druuna
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
12345

Last edited by druuna; 05-21-2009 at 10:10 AM..
  #3 (permalink)  
Old 01-05-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,798
If no lsof is on your system, then you may have fuser instead. Does pretty much the same.
  #4 (permalink)  
Old 01-05-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
I admit the following is not a good logic , but i'm not able to control sharing with you.

Place some type of identifier (special string) after first process finished writing into the file. and force the second process to look (grep) for that identifier (special string ) and continue the processing ....... copy ............whatever ...
  #5 (permalink)  
Old 01-05-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
My favorite way to handle this is to arrange for the producing program to produce two files: the real file, followed by a tiny flag file. When the flag file appears, you know that the first file is ready.
  #6 (permalink)  
Old 01-05-2005
98_1LE 98_1LE is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
A way I use to find growing log files on an unfamiliar system is:

Code:
touch /tmp/test
find /path/to/suspect -newer /tmp/test

A cheesy way you could do this is:

Code:
COUNT=`fuser /path/to/file | wc -c`
if [ $COUNT -gt 0 ]
   then echo file is open
fi

I am sure there is a better way than this, but I don't know what it would be in shell.
  #7 (permalink)  
Old 01-06-2005
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
We also like to use flag files, like Perderabo said. Just have your copy script #1 copy your data file into the directory and then upon success, touch a flag file. Then have copy script #2 check for the existence of the flag file. If the flag file is there, copy the script. If not, wait n minutes.

You also want to remove the flag file, either at the beginning of script #1 or the end of script #2.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0