Delete database table based on months using script.


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Delete database table based on months using script.
# 1  
Old 08-30-2007
Delete database table based on months using script.

HI All,

Newbie here.
I have a script which generates the tables in teradata database with time stamp like below.I want to add some more code to delete the archive tables which are 2months old.

. $HOME/.profile
t_name=$1
procdate=`date +%y%m%d`
log_dir=$Folder/log
tab=`echo $t_name"_"$procdate`
tab_create=$log_dir/$t_name.txt
param_dir=$Folder/parameter
echo ".run file=$param_dir/logon.txt;" > $tab_create
echo "DATABASE XYZ;" >> $tab_create
echo ".echoreq off;" >>$tab_create
echo ".SET FOLDLINE off; " >>$tab_create
echo "rename table $t_name to $tab;" >> $tab_create
echo ".if errorcode =3803 then .goto prob38;" >> $tab_create
echo "create table $t_name as $tab with no data;" >> $tab_create
echo ".quit;" >> $tab_create
echo ".LABEL prob38" >> $tab_create
echo "drop table $tab;" >> $tab_create
echo "rename table $t_name to $tab;" >> $tab_create
echo "create table $t_name as $tab with no data;" >> $tab_create
echo ".quit;" >> $tab_create
echo "EOF" >> $tab_create
bteq < $tab_create> $log_dir/$tab_create_$tab.log

Can someone help me on this..

Thanks.

Regards,
Mav.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to log file processing details to database table usnig UNIX shell script?

we are getting files on daily basis.we need to process these files. i need a unix shell script where we can count 1-The no of files processed 2-No of data/record processed for each files. The script should log these details into a database table. If there is any error while file... (3 Replies)
Discussion started by: Atul kumar
3 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. Shell Programming and Scripting

Intelligent Script to Insert Records in Database Table

Hello All Members, I am new to this forum and to the shell scripting. I want to write a shell script to do the following: Scenario: I have a pipe delimited .txt file with multiple fields in it. The very first row of the file contains the name of the column which resembles the name of the... (18 Replies)
Discussion started by: chetanojha
18 Replies

4. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

5. Shell Programming and Scripting

Delete folder in a directory which are two months old

I need help. I have to create a script which will delete multiple directory (folders) that are two months old. Example, I have folders dated April, May, June and July. I have to delete folders April and May and retain June and July and as such that when the July month lapse, the folder June will be... (2 Replies)
Discussion started by: jasperux
2 Replies

6. Shell Programming and Scripting

Script to count the dataflow in a table in oracle database

I need to write a unix shell script to connect to oracle database and retrieve data from a table, the script should count the total number of rows till date in that table number of rows which are getting filled per hour on current day and the peak hour of the current day number of rows which are... (5 Replies)
Discussion started by: PhAnT0M
5 Replies

7. Shell Programming and Scripting

Delete table from postgresql using shell script

Hi, I need help to Delete table from postgresql using shell script. Anyone know about it? Thanks Regards, Sajjad (1 Reply)
Discussion started by: sajjad
1 Replies

8. Shell Programming and Scripting

Delete oracle table from UNIX script

Hi, Is it possible to delete oracle table datas using a UNIX script/Shell script? how can we do this?? I have oracle Database and i have to delete millions of record everyday.. adn it is taking hours togather to execute this. Will the delete query triggered from UNIX be faster can we expect any... (1 Reply)
Discussion started by: Codesearcher
1 Replies

9. Shell Programming and Scripting

Sample ksh script for copy the data from excel to database table ?

Hi All, I need to convert the data from excel to database table in sybase. Please provide some sample script.. thanks, Royal. (1 Reply)
Discussion started by: royal9482
1 Replies

10. Shell Programming and Scripting

Delete 6 months old files

Hi, Iam trying to delete 6 months old files. Iam using the following script -ctime +190 -type f -exec echo rm {} \; Iam getting an error saying -ctime not found. (6 Replies)
Discussion started by: Sompalle Jalaja
6 Replies
Login or Register to Ask a Question
imqdbmgr(1M)						  System Administration Commands					      imqdbmgr(1M)

NAME
imqdbmgr - manage a plugged-in JDBC-compliant Message Queue data store SYNOPSIS
/usr/bin/imqdbmgr subcommand argument [ [option...]] /usr/bin/imqdbmgr -h | -help /usr/bin/imqdbmgr -v | -version DESCRIPTION
The imqdbmgr utility creates and manages a Java DataBase Connectivity (JDBC) compliant database used for Message Queue persistent storage. The database can be either embedded or external. To use a JDBC-compliant database (and the imdbmgr utility), you need to first set a number of JDBC-related properties in the broker instance configuration file. See the Sun Java System Message Queue Administrator's Guide for addi- tional information. imqdbmgr supports four management subcommands. These subcommands, and their corresponding arguments and options follow the imqdbmgr command on the command line. See USAGE and OPTIONS. The following subcommands are supported: create Create a Message Queue database schema. delete Delete Message Queue database tables in the current data store. recreate Delete Message Queue database tables and recreate Message Queue database schema in the curent data store. reset Reset the database table lock to allow other processes to access database tables. The imqdbmgr subcommands support the following arguments: all Indicates the subcommand applies to the data store, as well as the database tables. lck Indicates the subcommand applies to the database table lock. oldtbl Indicates the subcommand applies to an older version of the database tables. tbl Indicates the subcommand applies to the database tables only. OPTIONS
The following options are supported: -b brokerName Specify the broker instance name and corresponding instance configuration properties. If this option is not specified, the default broker instance is assumed. Use this option with the create, delete, recreate, or reset subcommands. -D property=value Set system property property to value. Use this option with the create, delete, recreate, or reset subcommands. -h | -help Display usage help. Execute nothing else on the command line. -p password Specify the database password. Use this option with the create, delete, recreate, or reset subcommands. -u userName Specify the database user name. Use this option with the create, delete, recreate, or reset subcommands. -v | -version Display version information. Execute nothing else on the command line. USAGE
The following subcommands and associated arguments are supported: create all Create a new embedded data store and Message Queue database schema for a specified or default broker instance. create tbl [-u userName] [-p password] Create Message Queue database schema in an existing data store for a specified or default broker instance. delete tbl [-u userName] [-p password] Delete Message Queue database tables in the current data store for a specified or default broker instance. delete oldtbl [-u userName] [-p password] Delete the earlier version of Message Queue database tables. Used after the data store has been automatically migrated to the current version of Message Queue. recreate tbl [-u userName] [-p password] Delete Message Queue database tables and recreate Message Queue database schema in the current data store for a specified or default broker instance. reset lck Reset the database table lock to allow other processes to access database tables. ENVIRONMENT VARIABLES
The following environment variables affect the execution of this command: IMQ_JAVAHOME Specify the Java 2 compatible runtime. When this environment variable is not set it defaults to /usr/j2se. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
/var/imq/instances/brokerName/dbstore Recommended directory in which to create an embedded database. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWiqu | +-----------------------------+-----------------------------+ SEE ALSO
imqadmin(1M), imqbrokerd(1M), imqcmd(1M), imqusermgr(1M), imqkeytool(1M), imqobjmgr(1M), attributes(5) Sun Java System Message Queue Administrator's Guide SunOS 5.11 29 Mar 2004 imqdbmgr(1M)