Difference between revisions of "Showactive"
Jump to navigation
Jump to search
m (changed tag) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 18: | Line 18: | ||
sub mysql { |
sub mysql { |
||
my ($sql) = @_; |
my ($sql) = @_; |
||
− | qx[mysql -s -u $database_username -p$database_password webwork << EOF |
+ | qx[mysql -s -u "$database_username" -p"$database_password" webwork << EOF |
$sql |
$sql |
||
quit |
quit |
||
Line 47: | Line 47: | ||
} |
} |
||
} |
} |
||
+ | |||
+ | |||
+ | [[Category:Scripts]] |
Latest revision as of 14:54, 21 June 2021
#!/usr/bin/perl # Showactive # Prints a list of active webwork users. # Author: Nandor Sieben @config= `cat $ENV{WEBWORK_ROOT}/conf/global.conf`; for $line (@config) { if ($line =~ /\$database_username.*=.*"(.+)"/) { $database_username = $1; } if ($line =~ /\$database_password.*=.*"(.+)"/) { $database_password = $1; } } sub mysql { my ($sql) = @_; qx[mysql -s -u "$database_username" -p"$database_password" webwork << EOF $sql quit EOF ]; } @tables= mysql(q[show tables like '%key';]); $ctime=time; foreach $table (@tables) { chop $table; next if ($table =~ /-/); # print "|$table|\n"; @rows=mysql(qq[select user_id, timestamp from $table]); foreach $row (@rows) { if ( $row =~ /(\S+)\s+(\S+)/) { $name=$1; $stamp=$2; $name =~ s/_.+//; $age =($ctime - $stamp) / 60; if ($age < 10) { $table =~ s/_key//; print "$table\t $name\t $age\n"; } } } }