Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a script which checks for the existance of 3 files and moves them to another server. These files have a constant filename (eg. abc1, abc2, abc3) The application which creates these files appends data to all 3 files per transaction. The files can contain multiple transactions. Files 1 & 2 always have a single line per transaction. File 3 can have multiple lines. This script will have to run as a cron job. How can I determine when it is safe to move the files off the server without splitting the transaction midway through creation.

If you attempt to move a file that is in the process of being updated then Windows won't let you. It will produce an error. All you need do is trap this error and try again later.
How you do this is dependant on what kind of script you are using.
Stuart

Whoops sorry about the above. I though I was in the Windows forum.
However, I should think the same applies to Unix. The OS should not let you move an open file.
Stuart

# Save a copy of incoming entries to abc1_catch too
tail -fn 0 abc1 | tee abc1_catch &# Make a copy of abc1
cp abc1 abc1_part# empty abc1. So, abc1 file is always available. Almost at the same time stop copying the entries to abc1_catch
> abc1;kill -9 `ps -ef|grep tail|grep -v grep|awk '{print $2}'# append the abc1_catch and abc1_whole is the file you need to move to another server
cat abc1_part abc1_catch > abc1_whole
Luke Chi

Thanks for the suggestion, but it won't work. I have to know if any of the 3 files are being written to as the transaction is spread over all 3 files and I have to keep the transaction intact for further manipulation and processing.

This script won't lose any appended data, but it is still possible to have the duplicated appended data. If these 3 files are log files, then the duplicated appended data can be ignored, else you have to remove them yourself.
For example: (It depends on your data and your application)
1. You may use id to locate and to remove the duplicated data
2. or You may run:
uniq abc1_whole > abc1_final
uniq abc2_whole > abc2_final
uniq abc3_whole > abc3_final# Save a copy of incoming entries to abc1_catch too
tail -fn 0 abc1 | tee abc1_catch &
tail -fn 0 abc2 | tee abc2_catch &
tail -fn 0 abc3 | tee abc3_catch &# Make a copy of abc1
cp abc1 abc1_part
cp abc2 abc2_part
cp abc3 abc3_part# empty abc1. So, abc1 file is always available. Almost at the same time stop copying the entries to abc1_catch
> abc1;> abc2;> abc3;kill -9 `ps -ef|grep tail|grep -v grep|awk '{print $2}'
# append the abc1_catch and abc1_whole is the file you need to move to another servercat abc1_part abc1_catch > abc1_whole
cat abc2_part abc2_catch > abc2_whole
cat abc3_part abc3_catch > abc3_wholeLuke Chi

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |