Copy or Move problem

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy or Move problem
# 1  
Old 09-09-2011
Question Copy or Move problem

Hi All,
I have a simple shell script to move .txt file(s) from a source directory one after another to the destination. The source directory is shared to windows using samba. The source files are arriving continuously and approx size is 10-15 KB. Some time the file size reached upto 100 KB and than the problem starts. The moving script is moving an incomplete file. Actually the file moving program is a continuous daemon which starts moving file immediately it appeared in the source. I have tried a sleep 2 before moving, but it's also failed in case the file is some more bigger than 100 KB. Smilie
Now I wanted to know is there any mechanism available to check if the source file is not in use by any other process? It means, I need to move or copy the file only when its being released by its producer process. It might be easier in Unix using ps command, but I don't know how to check it on a samba shared folder.
Can any body among you please give me a hand please?
# 2  
Old 09-09-2011
Use the fuser command to check the status.

fuser file

If the file is busy, you get some output(processes using the file). else back to command prompt.

# 3  
Old 09-09-2011
Hi guruprasadpr,

I have opened the 119703559.HL7 in another terminal and tried the one you have suggested in another terminal, but its not giving me any info.

12 [shivalpl1] dbadm % /usr/sbin/fuser 119703559.HL7

I have tried the same after exiting from vi mode, but both time the out put is same.

13 [shivalpl1] dbadm % !!
/usr/sbin/fuser 119703559.HL7
14 [shivalpl1] dbadm %

# 4  
Old 09-09-2011
Originally Posted by sraj142
The moving script is moving an incomplete file. Actually the file moving program is a continuous daemon which starts moving file immediately it appeared in the source

The way your script/Application is working is not recommended. In such cases, an another directory ( say "incomplete" )must be created which would be used to transfer the file from the first application and after the transfer is finished, the application itself should move the file to the "complete". your script must pick the file from the "complete" directory.
# 5  
Old 09-09-2011
Hi Anchal,

I have already tried the same. Still the incomplete file moving while the external application is moving the file to the source of my shell script. I think to check if the file is being used by any other process is the best option to choose. But unsure how to user "fuser" command here.
# 6  
Old 09-09-2011
vi does not keep the file open - you actually work on a hidden file. Use something like less to simulate an open file.
This User Gave Thanks to cero For This Post:
# 7  
Old 09-09-2011
WAH !!!!

Great Cero. Its worked for me. But couldn't store the pid in a valiable. Actually I wanted to check the length of the pid and if its more than 1 than sleep 5 or continue. I am using bash script here.
Please see if you can post a 2-3 line of examples here.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Separate the apache user file and move or copy some were

Hi all, I'm Using Centos 6.4 /opt/my_aplication/entry/data/0/ There are Thousands of files in this Directory, Only i need to copy or move the apache User's file from this to /tmp/backup , I have listed apache user's file using find . -user apache -type f , its gave me the only apache... (2 Replies)
Discussion started by: babinlonston
2 Replies

2. Solaris

Can't erase/move/copy file!

Hey everyone!. I have a problem with a file that doesn't allow any operation on it. I can't rm,mv,cp nor any other operation to it, I get the following errors: bash-2.05# mv ora_2527.aud /bkp mv: cannot access ora_2527.aud bash-2.05# cp ora_2527.aud /bkp cp: cannot access ora_2527.aud... (4 Replies)
Discussion started by: dragonov7
4 Replies

3. Shell Programming and Scripting

Copy/move file which are not currently in use.

Hello experts, I'm doing a shell script that able to copy or move files. My situation is i have a drive ( lets say its S drive) where its receive all the files from mainframe i need to copy all the file from S drive to T drive. but only those files that are finished copied from mainframe... (5 Replies)
Discussion started by: CelvinSaran
5 Replies

4. UNIX for Dummies Questions & Answers

Unable to copy or move file

I am trying to move a file that is in the root directory. I suspect it is an old file created by someone when the system was installed. I am testing accessing the file by doing a copy but the command does not find the file. I am operating as root. We are HP-UX B.11.23 I do long listing and... (3 Replies)
Discussion started by: phcorn
3 Replies

5. UNIX for Dummies Questions & Answers

help pls! need to move and copy pattern...

Help please... Need to convert below: Subcase ID : 10001 210000 0 1.22049E+01 220000 0 6.29560E+00 Subcase ID : 20703 210000 0 2.76398E+00 220000 0 2.43183E+00 230000 0 -1.87728E+01 Subcase ID : 13703 210000 0 ... (2 Replies)
Discussion started by: lakanino
2 Replies

6. UNIX for Dummies Questions & Answers

How to copy/move to a file with a special character as the 1st char in the filename?

I am trying to create files with special characters in its filenames for testing purposes. This is on a Linux RHEL4 but this should also be applicable on a Unix shell. I am able to create files with special characters in the filenames...e.g. cp -pv foo.gif \*special.gif cp -pv foo.gif \... (6 Replies)
Discussion started by: sqa777
6 Replies

7. Shell Programming and Scripting

Bash Copy-Move file problem

Hello, I made a script to copy files from one directory to another and move file after the copy is done. When files are present in the source directory there is no problem but when no file are present I'm getting an error. Please help !! --------------------- #!/bin/bash ... (2 Replies)
Discussion started by: lsimoneau
2 Replies

8. Shell Programming and Scripting

ncftp copy/move pb

Hi, i have made this script for copy file in folder FTP in my local machine, when copy is finish i move files copied in backups_001 directory on same ftp 1) the problem is if this script works with date if date is similar i taken, but if one day in ftp they put new file is no getting ... (0 Replies)
Discussion started by: livetele
0 Replies

9. Shell Programming and Scripting

Help with Copy Move Script

Hello Gurus! Please help! I would like to get some help with the following: I'm working right now on a Data Warehouse project and I need to automate a manual procedure I am using to process the data files coming into the database, any information/ideas and or which script language to go... (4 Replies)
Discussion started by: alfpathros
4 Replies

10. UNIX for Dummies Questions & Answers

how to copy/move folder on XP to Solaris?

I have created a folder on C:\images\Raffles.jpg on my PC, and I like to copy or move to Solaris server. How can I do that? Please advise. Thanks in advance. (2 Replies)
Discussion started by: simt
2 Replies
Login or Register to Ask a Question