Checking a file is not being written to


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking a file is not being written to
# 1  
Old 12-18-2005
Checking a file is not being written to

Hello All

I am attempting to write a shell script (bourne shell script) which will copy a tar'd and compressed file from a directory to a staging area but will not know whether the file is still open for write since files are being ftp's to my site at random times during the day.

Once I am convinced that the file is stable (not being written to) I will move it to another directory, uncompress it and untar it and then process the data.

What is a good way to determine that the file is not being written to (ftp from other site is complete) before I move it out of the directory in which it was ftp'd into.

thanks
Joe

p.s. please respond by email: EMAIL ADDRESS REMOVED
# 2  
Old 12-18-2005
From the rules you forgot to read:
Quote:
(10) Don't post your email address and ask for an email reply. The forums are for the benefit of all, so all Q&A should take place in the forums.
As for the question itself, that's tricky. Cooperative locking is possible, but both the shell and the FTP program would need to impliment that.
# 3  
Old 12-19-2005
try creating a trigger file

Let the job which ftp's create a trigger file(with some unique pattern) after it is done with the ftp. This would give you an idea of the completion of the file transfer.
# 4  
Old 12-19-2005
This has worked for me in the past.

Code:
lsof /path/2/file/getting/modified

An exit code of 0 shows file in use. 1 shows no activity on that file.

Code:
[/tmp]$ /usr/sbin/lsof ~/temp/test.tar
COMMAND   PID    USER   FD   TYPE DEVICE      SIZE    NODE NAME
cp      22551 xxxxxxx    4w   REG    3,1 202321920 8798213 /private/ora/temp/test.tar
[/tmp]$ echo $?
0
[/tmp]$ /usr/sbin/lsof ~/temp/test.tar
[/tmp]$ echo $?
1
[/tmp]$

vino
# 5  
Old 01-16-2006
How To Find File Is Transmig Or Transmtd

Hi vino

please tell what is lsof.when ever i tried to as man lsof it is failing.my actual problm is clearly what kanejm has wrriten.

i tried like files=`lsof ${ALTAS_IN_DIR}/IINV*.* 2>/dev/null`
after that depends on files value means that is zero or one proceeding(move the files to other directory.).

but error is lsof not found.thats i want know about lsof.

Regards,
MallikarjunaRao
# 6  
Old 01-16-2006
An error of 'lsof: not found' means that lsof is not available in your path. Check the value of the $PATH variable in your environment. Search for lsof on your box. Then add the path to lsof in the PATH variable in your environment. Here are the steps:
1.
Code:
echo $PATH

2.
Code:
whereis lsof

or (this may take quite a bit longer)
Code:
find /usr -name lsof -print

3.
Code:
PATH=$PATH:/path/to/lsof; export PATH

--EDIT--
mallikarjuna, in your code you are using *.* to pass filenames to lsof. I don't think that lsof can handle more than one filename at a time. Just check that out.
--/EDIT--
# 7  
Old 01-16-2006
What OS are you running ?

Post the results of uname -a

In my machine, lsof is /usr/sbin/lsof.

Follow what blowtorch says and you should find lsof.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if a file is open and in use (logs are being written to it)

Hello Experts, I need to write a shell script to check if a file is open and something is being written to it. I want to know how OS handles it. I checked with lsof command but it is not working. For a test I did this. while true; do echo `date` >>abc.txt; done then I checked lsof |... (5 Replies)
Discussion started by: shekhar_4_u
5 Replies

2. Shell Programming and Scripting

Notification as popups when a file being written

I would like to know Is it possible to get a notification as pop-up in linux when a folder with extension '.aqs' written a popup should come as " The folder has been written " Thank you in advance (5 Replies)
Discussion started by: bal_nair
5 Replies

3. UNIX for Advanced & Expert Users

How to copy a binary file while the file is being written to by another process

Hello, Can I copy a binary file while the file is being written to by another process? Another process (program) “P1” creates and opens (for writing) binary file “ABC” on local disk. Process P1 continuously write into ABC file every couple of seconds, adding 512-byte blocks of data. ABC file... (1 Reply)
Discussion started by: mbuki
1 Replies

4. UNIX for Dummies Questions & Answers

12. If an ‘88’ Record with BAI Code ‘902’ was found on input file and not written to Output file, re

This is my input file like this 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+00000000354,,/ 49,+00000000000416920,00002/ 03,5313236,,015,+00231036992,,,045,+00231036992,,,901,+00000048428,,/ 88,100,+0000000000000,0000000,,400,+0000000000000,0000000,/ 88,902,+0000000079077,,/... (0 Replies)
Discussion started by: sgoud
0 Replies

5. Shell Programming and Scripting

Apply Password to already Written XLS File.

I need to apply password protection to a xls file.I had looked at SpreadSheet::WriteExcel but problem being i dont want to write the contents of file again as the formatting the file would be a pain. Is there way in which i write a entire file in one go , something like this ... (0 Replies)
Discussion started by: dinjo_jo
0 Replies

6. UNIX for Dummies Questions & Answers

Appending something to output before being written to a file

Hi, I'm quite stuck with what I thought should've been simple but I just can't seem to do it. Firstly, I have the following done in bourne shell: cat datafile | tr '' '' >> newfile echo "$fullfilepath" >> newfile i want to have the output of that echo put on the same line as the output... (4 Replies)
Discussion started by: Darkst
4 Replies

7. Programming

Unix File has 000 access when written

Good day! I would just like to ask about an issue I encountered. There is a Java program (version1.3) that we use that is hosted in Unix (HP-UX B.11.11 U), and one of its functions copies a file and writes it to another directory. It usually runs fine, but one day, it wrote a file that had 000... (2 Replies)
Discussion started by: mike_s_6
2 Replies

8. UNIX for Dummies Questions & Answers

How the /etc/passwd file is written when user does not have permission

Hi, /etc/passwd file has write permission only for the root user. Now when a normal user changes the its own password using passwd command, how this information has been written to the /etc/passwd file when the user is not having write permission to this file. ~santosh (2 Replies)
Discussion started by: santosh149
2 Replies

9. UNIX for Dummies Questions & Answers

Operating on a file being written by another application

Hi, I have a directory that is used to store files generated by another application. Each file is huge and can take some time to produce. I am writing a shell script to check the names and dates of the files and do some functions on the ones that are not being written out. My question is, if I... (3 Replies)
Discussion started by: GMMike
3 Replies

10. UNIX for Dummies Questions & Answers

File being used/written

Hello, Which command in unix can tell whether a file is being used/written by another process. e.g. If one process is copying a very big file in some directory and there is another cronjob process which checks for a new file and in this directory and process the file. I want to check, if the... (4 Replies)
Discussion started by: sanjay92
4 Replies
Login or Register to Ask a Question