Writing a Perl Script which populates $step_info = "Preparing SQL for kill"; $get_sessions = $dbh->prepare( "sel 'kill session '||trim(sessionno (format '---------9')) from dbc.sessioninfo where accountname not like '%batch%' and accountname not like '%prod%' and accountname not like '%operator%' and accountname not like '%Crashdumps%' and accountname not like '%Smart%' and logonsource not like '%133.214.173.999%' and logonsource not like '%133.214.171.996%' and logonsource not like '%134.214.171.667%' and username not in ( sel * from sysadmin.kill_user_exclude);"); until ($hour == $until_hour) { $step_info = "Selecting users to kill"; $hour = `date '+%H'`; chomp $hour; $get_sessions->execute(); $get_sessions->bind_columns(\$rows); while ( $get_sessions->fetch() ) { push @kill_sessions, $rows; } if (@kill_sessions) { $step_info = "Executing /tgtw/bin/xgtwglobal -nw"; open(GATEWAY, "|/tgtw/bin/xgtwglobal -nw >> $ENV{LOGDIR}/$process/$prog.$date 2>&1"); print GATEWAY "sel host 52\n"; foreach $command (@kill_sessions) { print GATEWAY "$command\n"; } $get_sessions->finish(); $stmt_info = $get_sessions->{'tdat_stmt_info'}; $currstmt = $get_sessions->{'tdat_stmt_num'}; $stmthash = $$stmt_info[$currstmt]; $activity = $$stmthash{'ActivityType'}; $stmtrows = $$stmthash{'ActivityCount'}; $warn = $$stmthash{'Warning'}; $warn_stmt = "Statement $currstmt: $warn\n" if $warn; @date = `date`; $message = " $warn_stmt **** Statement Complete. **** $stmtrows sessions selected for death on @date $warn\n"; $total_kills = $total_kills + $stmtrows; print "$message\n"; print GATEWAY "quit\n"; close(GATEWAY); undef @kill_sessions; # Un-initialize the array for the next batch of sessions } sleep($every); # define a sleep time to wake up and get new logons or persistent users }