#!/usr/bin/perl -w # use Getopt::Std; use Time::Local; use diagnostics; use warnings; getopt('d:', \%params); my $database = uc($params{"d"}); die "Usage: $0 -d " unless ($database); my $result; $/ = undef; #connect db $result = `db2 connect to $database`; die "$0: Cannot connect to database $database.\n$result" unless ($? eq 0); #run db2 command $result = `db2 "select tabname from syscat.tables where STATS_TIME >= TRUNC(current timestamp) - 7 days and TABSCHEMA = 'TCSUPER'"`; my $close = `db2 connect reset`; die "$0: Cannot close connection to database $database.\n$close" unless ($? eq 0); `db2 terminate`; # print current timestamp my $now = `date`; print "$now\n"; @records = split(/\n/, $result); ## removing last element in array. my $retval = pop(@records); $cnt = 1; $table_list = ""; foreach my $record (@records) { ## remove headers in the results if ($cnt > 3 ) { #trim white spaces $record =~ s/^\s+//; $record =~ s/\s+$//; if (length($record) > 0 ) { print "$cnt : |$record| " . length($record) . "\n"; $table_list .= " " . $record; ##print "$table_list\n"; } } $cnt++; } print $table_list; #excute db2look from the table lists `db2look -d tcard -m -t $table_list -o dl.out`; exit; ~