File name should not be captured if still copying


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File name should not be captured if still copying
# 1  
Old 01-23-2011
File name should not be captured if still copying

HI,

I am running a shell script on a folder where our sources files will be published for every 5 mins, I am copying all the source files(i.e .csv format) to a .txt as ls *.csv > camp.txt.

Now when the above command is executing some files which are not copied completely , their name is also getting captured in the camp.txt, is there any way we can exclude all the files which are copying state i.e files which are not copied completely from source to destination can be excluded from writing into the camp.txt


example

a.csv copied completely
b.csv copied completely
c. csv coping started but not finished 100%

my result should include.

camp.txt
a.csv
b.csv


please help me in how to exclude the files in the copying state.

Thanks,subhasri
# 2  
Old 01-23-2011
Assumin that this "ls" is running on the destination directory independently of the copy process and sometimes executes while the copy process is still running or perhaps after the copy process has failed.
I guess that you will need to copy the files to a temporary filename, then rename the files to their correct name after to copy completes. The convention is to append ".tmp" to the real filename (e.g. a.csv.tmp).
# 3  
Old 01-23-2011
so how about this way:

Prepare pair of cvs file, and its md5 file, every name.cvs should have a md5 file: name.cvs.md5

so before list the cvs name to camp.txt, check its md5 hash key in name.cvs.md5 is same as the real md5 hash key.

Last edited by rdcwayx; 01-23-2011 at 11:28 PM..
# 4  
Old 01-23-2011
HI,

I didn't get the .tmp thing, when the source files are in copying state in the source directory they are not having any .tmp extension , this process will be required for a datamigration application so after the file is copied in the source directory with in 30 mins it has to be loaded in the table so copying the source files to temp location will delay that process.

And I haven't got the md5 hash key stuff, how can we check that can you please give me some more details.

Thanks,
Subhasri
# 5  
Old 01-23-2011
in solaris system, there is a command md5 (or md5sum), maybe the name is different in other systesms.

Code:
$ md5 1.csv
9c02cfb4ae36f88fcf71c8047169da74        1.csv

you can build the md5 key list in pair of csv file

before list, check the md5 key if they are same.
# 6  
Old 01-23-2011
Quote:
Originally Posted by subhasri_2020
HI,

I didn't get the .tmp thing, when the source files are in copying state in the source directory they are not having any .tmp extension , this process will be required for a datamigration application so after the file is copied in the source directory with in 30 mins it has to be loaded in the table so copying the source files to temp location will delay that process.
The original proposal was to give the file a different name when it is being copied and then move to the final name once done. eg: mv /my/migration/dir/Monday_0124.txt.tmp /my/migration/dir/Monday_0124.txt

The mv command should operate pretty much instantaneously when the source and destination filenames are within the same filesystem, as this only involves an update of the File table, not a physical move (or copy) of the bytes within the file.
# 7  
Old 01-23-2011
If you can't control the published file extension (i.e. the .tmp suggestion), you might check if the file is still open with the fuser command and discard any file in the o (open) state.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying a file to multiple other files using a text file as input

Hello, I have a file called COMPLIST as follows that contains 4 digit numbers.0002 0003 0010 0013 0015 0016 0022 0023 0024 0025 0027 0030 0031 0032 0033 0035 0038 0041 (3 Replies)
Discussion started by: sph90457
3 Replies

2. Shell Programming and Scripting

tcpdump script to parse "packers captured" details

I want a script that would do as:- a) gives me packet capture account for each time it runs. b) be able to run at a particular time for specific period time duration (1 min). c) for each time it runs it saves the time / day. Is there a way where i can capture the details as seen in the... (2 Replies)
Discussion started by: lazerz
2 Replies

3. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

4. Shell Programming and Scripting

[Solved] Output in bash script not captured in variable

I'm tring to write down a simple script that would execute a command and wait until it returns a specific result. This is what i did: bjobs_out=`bjobs` while ]; do bjobs_out=`bjobs` sleep 6 done It seems to work until the command 'jobs' return the list of jobs in execution, but... (4 Replies)
Discussion started by: lifedj
4 Replies

5. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

6. Shell Programming and Scripting

return code not captured

Hi all, We have a script in our Unix box(HP-UX 11.11) which is invoked as script1.sh param1 param2 >>${logfile} script2.sh "param" Actually the script2 is also called from the same line. There is no semicolon between the 2 calls. I also checked the octal dump. What happens here... (2 Replies)
Discussion started by: ranj@chn
2 Replies

7. Filesystems, Disks and Memory

Strange difference in file size when copying LARGE file..

Hi, Im trying to take a database backup. one of the files is 26 GB. I am using cp -pr to create a backup copy of the database. after the copying is complete, if i do du -hrs on the folders i saw a difference of 2GB. The weird fact is that the BACKUP folder was 2 GB more than the original one! ... (1 Reply)
Discussion started by: 0ktalmagik
1 Replies

8. UNIX for Dummies Questions & Answers

Informix function return value needs to be captured in shell script

I need to run a 4ge from within my shell script and capture the string value that is being returned into a unix variable. I have tried the back ticks to no avail. I know it is returning because I did get the returned value to go to my screen at one point.. What I have is: sendlist =... (3 Replies)
Discussion started by: jeniferz
3 Replies

9. Cybersecurity

Reading and Manipulating captured packets (pflog file)

Hey, I currently have a set of captured sessions thru ethereal, saved in pflog files, basically its a tcpdump, which i need to go thru and sort the applications/protocols in order of the times they were used. I also need to change the headers of the packets, basically the source and destination... (0 Replies)
Discussion started by: PenguinDevil
0 Replies
Login or Register to Ask a Question