Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to act on ".chm" files only

Status
Not open for further replies.

chippymike

Technical User
Apr 16, 2003
22
GB
Hi All,

I'm looking for a solution to the following problem.....

1) Files are transferred to a directory (/dir_path/import) from another server using FTP.
2)Once the FTP process is complete the script renames the file from "*.chm.tmp" to ".chm" - In other word the ".tmp" extension is dropped.
3)Our present script then moves the file from /dir_path/import to /dir_path/process and changes the ".chm" extension to a ".imp" extension.
4) At present the script acts on the files which still have a ".tmp" extension - i.e. before the FTP process is complete.

I need the script to act on files with a ".chm" extension only.I thought that something like this would go some way to solving the problem but it won't even compile.


if [ -f ${PROCESSDIR}/${PROD_FILE_PREFIX}.tmp ]
then
logit ${PROD_FILE_PREFIX}.tmp exists on $PROCESSDIR
else
logit No files with the .tmp extension were found
continue

# If a .tmp file is found, check that it is complete (i.e. not growing)

GROWING=1
while [ GROWING -eq 1 ]
do
_size=`ls -l ${PROCESSDIR}/${PROD_FILE_PREFIX}.tmp | cut -c32-41`
sleep 60 # wait a minute
_size_now=`ls -l ${PROCESSDIR}/${PROD_FILE_PREFIX}.tmp | cut -c32
-41`
if [ $_size = $_size_now ]
then
GROWING=0
fi
done

# Now check if the file contains records ; 0 byte files can be deleted

if [ -s ${PROCESSDIR}/${PROD_FILE_PREFIX}.tmp ]
then
# mail support
logit ${PROCESSDIR}/${PROD_FILE_PREFIX}.tmp file found
messageOperator $DATE 00019 ${PROCESSDIR}/${PROD_FILE_PREFIX}.tmp
fi


I know it's asking a lot but any help would be greatly appreciated!

Cheers!
 
Hi All,

In update to my own problem........

The above script is only a very small section of a much larger one.
I think I may have found the solution myself.

If I modify this "for" loop to prevent the script from acting on "field 2" and make it act on ".chm" files only, would this stop ".tmp" files being transferred?

How would I make the script look for ".chm" files only and not ".tmp" files?


for HELD_FILE in `ls -1`
do
FILE_NAME_UC=`echo $HELD_FILE|cut -d "." -f2`
FILE_NAME=`echo $HELD_FILE|cut -d "." -f2`
FILE_NAME_SEQNO=`echo $HELD_FILE|cut -d "." -f1`
# Get the production file name
FOUND=`cat $FILELIST|grep $FILE_NAME|cut -d "," -f2|wc -l`
if [ $FOUND -eq 0 ]
then
logit Unable to find production filename for $HELD_FILE
messageOperator $DATE 00008 $HELD_FILE
continue
else
PROD_NAME=`cat $FILELIST|grep $FILE_NAME|cut -d "," -f2`
PROD_PREFIX=`echo $PROD_NAME|cut -d "." -f1`
fi

# Check that the previous live file ( .imp, .ERR or .ER1 )
# has been processed

if [ ! -f $PROCESSDIR/${PROD_PREFIX}* ]
then
# See if this is the next sequence number expected to process.

SEQ_NO=`cat $CTLLIB/${FILE_NAME}.last.proc.no`
EXPECTED_SEQNO=`expr $SEQ_NO + 1`
if [ $FILE_NAME_SEQNO -eq $EXPECTED_SEQNO ]
then
# Rename and move the file to the import directory ready to be proce
ssed
mv $HELD_FILE $PROCESSDIR/$PROD_NAME
if [ $? -ne 0 ]
then
logit Unable to rename $HELD_FILE to $PROD_NAME
messageOperator $DATE 00010 $HELD_FILE $PROD_NAME
else
logit $HELD_FILE moved to import directory as $PROD_NAME
echo $FILE_NAME_SEQNO > $CTLLIB/${FILE_NAME}.last.proc.no
fi
else
logit Held file:$HELD_FILE sequence number - $FILE_NAME_SEQNO
logit is not the next one expected $EXPECTED_SEQNO
messageOperator $DATE 00012 $HELD_FILE $EXPECTED_SEQNO
fi
else
logit Unable to move $HELD_FILE as production file still being proces
sed
fi
done


Thanks for your help!

 
Replace all instances of .tmp with .chm
Remove the 'growing' section - its after the Ftp
so they are complete files anyway
HTH

Dickie Bird (:)-)))
 
Thanks Dickie Bird!

Do you think that adding this line to the top of the "for" loop (replacing the one that's there already) would do enough without me needing any of the syntax in my first post?

for HELD_FILE in `ls -1 |grep -v tmp$`
do
etc....................

By the looks of it I think it probably would.......

Cheers
 
or this....

for HELD_FILE in `ls -1 |egrep chm.tmp`
do
etc................

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top