Here is a solution. Thanks for the help. Nandor
#!/usr/bin/perl
# Prints a list of active webwork users. Assumes sql_single layout.
# Author: Nandor Sieben
$password = 'mysqlrootpassword';
sub mysql {
my ($sql) = @_;
# print "$sql";
qx[mysql -s -u root -p$password webwork << EOF
$sql
EOF
];
}
@tables= mysql(q[show tables like '%key';]);
$ctime=time;
foreach $table (@tables) {
chop $table;
@rows=mysql(qq[select user_id, timestamp from $table]);
foreach $row (@rows) {
if ( $row =~ /(S+)s+(S+)/) {
$name=$1;
$stamp=$2;
$age =($ctime - $stamp) / 60;
if ($age < 10) {
$table =~ s/_key//;
print "$table\t $name\t $age\n";
}
}
}
}
<| Post or View Comments |>
|