shell script for archive purge


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script for archive purge
# 1  
Old 10-13-2008
shell script for archive purge

I am writing a shell script for Archive Purge for the table having rows < 1 year. The shell script has to extract the rows from the table and write those extracted rows to a text file. Then from the text file, each rows will be read and deleted by means of delete query one by one. The fields will be defined by means of position.

For Eg. ZB_RCVBL_TRACKER consists of the fields as follows.
PCN, ACCNO, TRANCD, AMOUNT, LOB_TIMESTAMP
After the rows are extracted and written in to a text file. I need to get the fields PCN, ACCNO, TRANCD, LOB_TIMESTAMP from the text file and pass those values to the query

DELETE FROM ZB_RCVBL_TRACKER where PCN = ? and ACCNO=? and TRANCD = ? and LOB_TIMESTAMP = ?

If the SQLCODE is 0, I can proceed furthur.

Can anyone help me to achieve this task.

Code:
==================================
#! /bin/ksh
############################
#   AFI Monitor Script
############################

. /db2/uszlad48/sqllib/db2profile
export mondir=/home/bmwdev1/script/krishna
export monlog=$mondir/Error_Report_`date +%Y%m%d`.log

export bakdir=/home/bmwdev1/script/krishna/bkup
export baklog=$bakdir/Error_Report_`date +%Y%m%d`_bkup.log

# connect to DB
#echo "connect to database r2pdev" >>$monlog

# extract the eligible rows from the table
db2 "SELECT * FROM ZB_RCVBL_TRACKER WHERE TIMESTAMP_UPDATED < (SYSDATE - 1 YEAR)WITH UR"  >> $monlog
echo "After SQL execution" >> $monlog
==================================



Krishnakanth
# 2  
Old 10-13-2008

Code:
while read PCN ACCNO TRANCD AMOUNT LOB_TIMESTAMP
do

   db2 "DELETE FROM ZB_RCVBL_TRACKER where PCN = $PCN and \
       ACCNO=$ACCNO and TRANCD = $TRANCD and LOB_TIMESTAMP = $LOB_TIMESTAMP" || break

done < "$FILE"

# 3  
Old 10-14-2008
Thank you for your reply Johnson.

Here the problem is how to read PCN, ACCNO, TRANCD, AMOUNT, LOB_TIMESTAMP from a text file. The data will be as follows in the text file.

Quote:

9564587 111222333 AD 563.85 2008-10-01-00.00.00.000000
9564588 111222334 AE 567.85 2008-10-02-00.00.00.000000
9564589 111222335 AF 963.85 2008-10-03-00.00.00.000000
9564590 111222336 AH 566.85 2008-10-04-00.00.00.000000
The data existing in a text file is a raw data. The length of each field is fixed length.
Is it possible to do like as follows.
pcn is 7 byte starting from 1 to 7
accno is 9 byte starting from 9 to 17
tran_cd is 2 byte starting from 19 to 20
amount is 8 byte starting from 22 to 29
LOB_TIMESTAMP is 26 byte starting from 30 to 55

can we define like this and will pass data. If so how to define in shell script ?

Could you please let me know how to proceed furthur.

Krishnakanth
# 4  
Old 10-14-2008

What's wrong with the script I posted?
# 5  
Old 10-14-2008
Johnson,

The script that you have given works fine. But in my case it is a different one.

I have given the sample what I am working now. Let me give you the exact one what i am working currently.

following is the data in a text file.(db2 "SELECT TRACKING_NUM, TRACKING_NUM_SUFFIX, ERROR_SRC_CD, MSG_NUM, MSG_ID, MSG_TYP, MSG_TEXT, TIMESTAMP_UPDATED, USER_UPDATED FROM ZB_RCBL_ERROR_MSG_MIG WITH UR" >> $monlog1)

Quote:
12345 10 E-123 - - - Hello - -
12345 10 E - - - Hello - -
12345 10 A - - - Hello - -
12345 10 T - - - Hello - -
1234 15 - - - - ERROR - -
123456 10 - - - - ERRORS - -
123456 10 - - - - ERRORS - -
255678 200 - - - - ERRORCORRECTION - -
255678 200 - - - - ERRORCORRECTION - -
1111111111 10 - - - - - - -
7890 10 ERRORMSG 90 78 E ERROR 2008-08-11-06.53.12.924263 R2P
12345 11 eadf j123 10 E this is emsg 2008-08-11-14.05.11.745265 -
12345 11 eadf j123 10 E this is emsg 2008-08-12-09.39.38.886385 -
12345 11 eadf j123 10 E this is emsg 2008-08-12-09.42.21.223536 -
12345 11 eadf j123 10 E this is emsg 2008-08-12-09.48.57.911702 -
12345 11 eadf j123 10 E this is emsg 2008-08-12-09.49.59.296360 -
22345 11 error j123 10 E this is an emsg 2008-08-12-10.08.33.843147 hello
255679 25 - - - - - - -
BEYJYWG83L 0 R 902 - B System Exception Occured, please refer to BMW_EXCEPTION_LOG table 2008-09-10-00.41.32.787352
BEYJYXMT4K 0 R 902 - B System Exception Occured, please refer to BMW_EXCEPTION_LOG table 2008-09-11-19.01.23.878551
BEYEHF93QY 0 R 003 B No message exists in ZBV_BILL_REJCT_RSN table 2008-08-28-16.31.01.881717
BEYJYTT8FQ 0 R 013 B Invalid Transaction Code 2008-09-04-17.39.04.005237
BEYJYTT8FQ 0 R 016 B Invalid Fee Code 2008-09-04-17.39.04.008137
BEYJYTT8FQ 0 R 016 B Invalid Fee Code 2008-09-04-17.39.04.011939
BEYJYTT8FQ 0 R 016 B Invalid Fee Code 2008-09-04-17.39.04.012851
BEYJY2SZVL 0 R 003 B Policy / Contract Account Number are pending in the ZB_MASTER_DATA_LOG 2008-09-16-09.22.29.120192
BEYJY2SXNG 0 R 003 B Policy / Contract Account Number are pending in the ZB_MASTER_DATA_LOG 2008-09-16-09.19.33.868772
BEYJY2SMS3 0 R 003 B Policy / Contract Account Number are pending in the ZB_MASTER_DATA_LOG 2008-09-16-08.53.07.872138
BEYJY2SMJD 0 R 003 B Policy / Contract Account Number are pending in the ZB_MASTER_DATA_LOG 2008-09-16-08.50.17.307262
BEYJY2EG2K 0 R 003 B Policy / Contract Account Number are pending in the ZB_MASTER_DATA_LOG 2008-09-17-15.56.03.418917
002211556 0 R 001 B Identical Receivable transaction has already posted for this policy. 2008-09-19-01.41.01.454234
002211556 0 R 002 B One or more uncleared errored receivables for the policy 2008-09-23-01.36.07.982876
002211556 0 R 002 B One or more uncleared errored receivables for the policy 2008-09-23-01.38.44.515880
002211556 0 R 001 B Identical Receivable transaction has already posted for this policy. 2008-09-23-16.32.20.565704
6634583444 0 R 902 - J System Exception Occured, please refer to BMW_EXCEPTION_LOG table 2008-09-15-12.44.09.383234

If I give the following script.

Quote:
while read TRACKING_NUM TRACKING_NUM_SUFFIX ERROR_SRC_CD MSG_NUM MSG_ID MSG_TYP MSG_TEXT TIMESTAMP_UPDATED USER_UPDATED
do

db2 "SELECT TRACKING_NUM, TRACKING_NUM_SUFFIX, ERROR_SRC_CD, MSG_NUM, MSG_ID, MSG_TYP, MSG_TEXT, TIMESTAMP_UPDATED, USER_UPDATED FROM ZB_RCBL_ERROR_MSG_MIG WHERE TRACKING_NUM = $TRACKING_NUM AND TRACKING_NUM_SUFFIX = $TRACKING_NUM_SUFFIX AND TIMESTAMP_UPDATED = $TIMESTAMP_UPDATED WITH UR" >> $monlog2

done < "$FILE"
The script that you have given is not working in this case. Bacause the value of the field MSG_TEXT is like "Identical Receivable transaction has already posted for this policy." 73 bytes long.

Please let me know how to proceed furthur.

Krishnakanth
# 6  
Old 10-14-2008

Please put code and sample data inside [code] tags, not [quote] tags.

Test the script by echoing the command instead of executing it.
Code:
echo db2 "SELECT TRACKING_NUM, TRACKING_NUM_SUFFIX, ERROR_SRC_CD, MSG_NUM, MSG_ID, MSG_TYP, MSG_TEXT, TIMESTAMP_UPDATED, USER_UPDATED FROM ZB_RCBL_ERROR_MSG_MIG WHERE TRACKING_NUM = $TRACKING_NUM AND TRACKING_NUM_SUFFIX = $TRACKING_NUM_SUFFIX AND TIMESTAMP_UPDATED = $TIMESTAMP_UPDATED WITH UR"

Make sure that the line you have built is correct before removing the echo.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

2. Homework & Coursework Questions

Archive and purge the log file

Hi Unix Experts, I am new in this filed. I have assignment to Archive and purge the log file using shell scripts I tried I could not get the result please help me this. Ex: test.log requirement : using shell script I need to archive the log file and nil and the content of (test.log)... (1 Reply)
Discussion started by: johney1981
1 Replies

3. Shell Programming and Scripting

Archive shell script

Hi, I'm new to Unix shell scripting and my first task is proving to be tricky. Please help where you can with pointers, tips, or examples of script. I'm self learning from the internet. I need to archive off files to another write protected directory according to the file names. ex.... (0 Replies)
Discussion started by: gorses
0 Replies

4. Shell Programming and Scripting

Purge files and archive

Hi Friends, I have an urgent requirement. I have many files huge in size which has occupied almost the entire disk space. The files are not being moved to the archived folder. But at present I need to purge those files, new to shell scripting, not sure how to proceed. Eg. Directory... (3 Replies)
Discussion started by: unx100
3 Replies

5. Shell Programming and Scripting

ftp, archive, email and delete from shell script

Hello, I found the forum’s information very helpful and informative. I am relatively new to UNIX programming. I am researching how to write a UNIX shell script to ftp all files from specific host folder to a client server. Also need to archive all transferred files, send a message (email) if any... (4 Replies)
Discussion started by: Lenora2009
4 Replies

6. Shell Programming and Scripting

Shell script to check the files hourly and purge

I'm new to shell scripting... i have been given a task.. can any one help in this regard.... 1) Check hourly for files in <destination-path><destination-file-template><destination-file-suffix> for files older than <destination-file-retention> days and purge. It should then check... (1 Reply)
Discussion started by: satishpabba
1 Replies

7. Shell Programming and Scripting

shell script for primary and standby DB archive log check

Hi All, OS:AIX 5.3 64 bits I would like the below script to send alert mail with the message - "Standby logs falling behind Primary" to xyz@yahoo.com Script ===== #!/usr/bin/ksh #----------------------------------------------------------------------------- # Use SQL*Plus to query... (1 Reply)
Discussion started by: a1_win
1 Replies

8. Shell Programming and Scripting

script to archive and purge

Hi, I am writing a shell script for archive data from a table. The design is as follows. Step 1: Execute the select query and extract the data into a text file. Step 2: The primary key for this table is TRACKING_NUM, TRACKING_NUM_SUFFIX, TIMESTAMP_UPDATED. So These three fields will be read... (1 Reply)
Discussion started by: kmanivan82
1 Replies

9. Shell Programming and Scripting

Generic Shell Script to Archive a file

Would appreciate if any one can paste a generic schell script to archive a file with date stamp by passing the file with fullpath as parameter For Eg. /apps/scripts/Archive_File.sh /data_home/project_home/file.txt this should place the file in the following directory ... (8 Replies)
Discussion started by: mak1600
8 Replies

10. Shell Programming and Scripting

Read from file then purge or archive.

Hi All, I have a root directory /tmp and I want to purge files or archive files in its subsequent subfolders.I listed the path of files I want to purge(archive) and the #of days. (purge) DAYS PATH 7 /tmp/arsenal/* 5 /tmp/chelsea/* (archive? the same as above but different folders... (15 Replies)
Discussion started by: kayarsenal
15 Replies
Login or Register to Ask a Question