How to check a file in UNIX is closed or growing?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to check a file in UNIX is closed or growing?
# 1  
Old 01-05-2005
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  
Old 01-05-2005
12345

Last edited by druuna; 05-21-2009 at 10:10 AM..
druuna
# 3  
Old 01-05-2005
If no lsof is on your system, then you may have fuser instead. Does pretty much the same.
# 4  
Old 01-05-2005
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  
Old 01-05-2005
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  
Old 01-05-2005
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  
Old 01-06-2005
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to check if my log file is growing properly?

Hi All, I want to check if one my log file is updating properly, how can I achieve it. The approach I am trying is to get the file size at two different interval and than comparing it eg : $ ls -ltr | tail -1 | awk '{print $5}' 20480 (7 Replies)
Discussion started by: mukulverma2408
7 Replies

2. UNIX for Advanced & Expert Users

Incremental extract from growing log file.

We have a log file which has 16 million row. We want to read all the lines appended from the last time we read using sed command sed -n '<START_LINE>,<LAST_LINE>p' abc.csv I can store this last line line so I can give replace that with START_LINE in my next read. The problem is wc -l which... (2 Replies)
Discussion started by: one2connect
2 Replies

3. Shell Programming and Scripting

Error check for copying growing directories

I have a simple script which copies directory from one place to another and deleting the source . I am facing a situation when new files gets added when the script has started running. Its resulting in data loss Please suggest a way to avoid data loss. I googled a lot but most are perl... (11 Replies)
Discussion started by: ningy
11 Replies

4. UNIX for Dummies Questions & Answers

Find the file which is growing at high speed

Hi, A log file which is growing at high speed, don't know the name of it. How to find the respective file? Many thanks. (2 Replies)
Discussion started by: venkatesht
2 Replies

5. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

6. Solaris

Growing a file system-SVM

Hi gurus Im a newbie in solaris..I need to extend file system space in solaris 10 which is using SVM..I have a file system /pin02 which is 93% full n needs to be extended..only 3.6 gb avail space left..the file system is not mirrored...normal ufs file system only..can u please tel me t... (6 Replies)
Discussion started by: madanmeer
6 Replies

7. HP-UX

how to redirect the growing contents of log file to another file in unix

how to redirect the growing contents of log file to another file in unix (2 Replies)
Discussion started by: megh
2 Replies

8. UNIX for Dummies Questions & Answers

Find out the maximum growing file in a mount

I need to find the file that is growing in the mount. Say yesterday the utilised space was 95% but today that is 96%. How do i find the file that is growing in size. Have checked the same with du/df options but was not able to find much. Please suggest the best possible option. (3 Replies)
Discussion started by: raman1605
3 Replies

9. UNIX for Dummies Questions & Answers

.osm file growing

my /etc/.osm file is growing rapidly and logging large amounts of activity. Can anyone tell me what this file is for and what types of information is logged in this file. Thanks in advance for your help!! (1 Reply)
Discussion started by: golfs4us
1 Replies

10. Shell Programming and Scripting

how can i check if text file is closed ?

Hello all im trying to make daemon that listen for incoming textiles and then it will move them to defined directory now the daemon part is ok but im stack on how to check of file is close and done copied to directory . so i could process it and move it forward tnx (13 Replies)
Discussion started by: umen
13 Replies
Login or Register to Ask a Question