Sponsored Content
Full Discussion: Please help!!!
Top Forums Shell Programming and Scripting Please help!!! Post 302081090 by reborg on Friday 21st of July 2006 11:28:08 PM
Old 07-22-2006
Changed a good bit, so I'll post a whole script again, however only the awk part has changed, there are a few changes, so please double check you've got them all if you have problems. I have tested this and it does work.

Code:
#! /usr/bin/ksh
dat=/biddf/ab6498/dev/ctl
cd $dat
files=CARE01_DLY_???_`date '+%Y%m%d'`


awk '{data[NR] = $0; out=FILENAME "new"; file[NR]=out;} END { if ( FNR - 2 != $1) { print "error" ; exit 1 } if ( ARGIND == --ARGC ){ for ( i=2 ; i < NR; i++ ) { print data[i] > file[i] }  close(file[i])}}' $files

 
IO::AtomicFile(3)					User Contributed Perl Documentation					 IO::AtomicFile(3)

NAME
IO::AtomicFile - write a file which is updated atomically SYNOPSIS
use IO::AtomicFile; ### Write a temp file, and have it install itself when closed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->close || die "couldn't install atomic file: $!"; ### Write a temp file, but delete it before it gets installed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->delete; ### Write a temp file, but neither install it nor delete it: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->detach; DESCRIPTION
This module is intended for people who need to update files reliably in the face of unexpected program termination. For example, you generally don't want to be halfway in the middle of writing /etc/passwd and have your program terminate! Even the act of writing a single scalar to a filehandle is not atomic. But this module gives you true atomic updates, via rename(). When you open a file /foo/bar.dat via this module, you are actually opening a temporary file /foo/bar.dat..TMP, and writing your output there. The act of closing this file (either explicitly via close(), or implicitly via the destruction of the object) will cause rename() to be called... therefore, from the point of view of the outside world, the file's contents are updated in a single time quantum. To ensure that problems do not go undetected, the "close" method done by the destructor will raise a fatal exception if the rename() fails. The explicit close() just returns undef. You can also decide at any point to trash the file you've been building. AUTHOR
Primary Maintainer David F. Skoll (dfs@roaringpenguin.com). Original Author Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com). REVISION
$Revision: 1.2 $ perl v5.18.2 2005-02-10 IO::AtomicFile(3)
All times are GMT -4. The time now is 05:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy