The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perform action file name written to the pipe fed.linuxgossip Shell Programming and Scripting 2 07-23-2008 11:38 AM
Checking for a file in file pattern before deleting it dsrookie UNIX for Dummies Questions & Answers 1 05-09-2008 05:29 PM
Error checking a file from previous file size stuck1 Shell Programming and Scripting 2 12-06-2007 08:39 AM
Operating on a file being written by another application GMMike UNIX for Dummies Questions & Answers 3 02-01-2005 04:06 PM
File being used/written sanjay92 UNIX for Dummies Questions & Answers 4 10-13-2001 02:31 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 12-18-2005
kanejm kanejm is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 4
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 (permalink)  
Old 12-18-2005
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,960
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 (permalink)  
Old 12-19-2005
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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 (permalink)  
Old 12-19-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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 (permalink)  
Old 01-16-2006
mallikarjuna mallikarjuna is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 8
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 (permalink)  
Old 01-16-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 (permalink)  
Old 01-16-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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.
Closed Thread

Bookmarks

Tags
linux

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 09:48 AM.


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