Difference between revisions of "Showactive"
Jump to navigation
Jump to search
(Created page with "#!/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) { i...") |
|||
Line 1: | Line 1: | ||
− | #!/usr/bin/perl |
+ | #!/usr/bin/perl |
− | + | ||
− | # Showactive |
+ | # Showactive |
− | # Prints a list of active webwork users. |
+ | # Prints a list of active webwork users. |
− | # Author: Nandor Sieben |
+ | # Author: Nandor Sieben |
− | + | ||
− | @config= `cat $ENV{WEBWORK_ROOT}/conf/global.conf`; |
+ | @config= `cat $ENV{WEBWORK_ROOT}/conf/global.conf`; |
− | + | ||
− | for $line (@config) { |
+ | for $line (@config) { |
− | if ($line =~ /\$database_username.*=.*"(.+)"/) { |
+ | if ($line =~ /\$database_username.*=.*"(.+)"/) { |
− | $database_username = $1; |
+ | $database_username = $1; |
− | } |
+ | } |
− | if ($line =~ /\$database_password.*=.*"(.+)"/) { |
+ | if ($line =~ /\$database_password.*=.*"(.+)"/) { |
− | $database_password = $1; |
+ | $database_password = $1; |
− | } |
+ | } |
− | } |
+ | } |
− | + | ||
− | 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 |
− | EOF |
+ | EOF |
− | ]; |
+ | ]; |
− | } |
+ | } |
− | + | ||
− | @tables= mysql(q[show tables like '%key';]); |
+ | @tables= mysql(q[show tables like '%key';]); |
− | + | ||
− | $ctime=time; |
+ | $ctime=time; |
− | + | ||
− | foreach $table (@tables) { |
+ | foreach $table (@tables) { |
− | chop $table; |
+ | chop $table; |
− | next if ($table =~ /-/); |
+ | next if ($table =~ /-/); |
− | # print "|$table|\n"; |
+ | # print "|$table|\n"; |
− | @rows=mysql(qq[select user_id, timestamp from $table]); |
+ | @rows=mysql(qq[select user_id, timestamp from $table]); |
− | foreach $row (@rows) { |
+ | foreach $row (@rows) { |
− | if ( $row =~ /(\S+)\s+(\S+)/) { |
+ | if ( $row =~ /(\S+)\s+(\S+)/) { |
− | $name=$1; |
+ | $name=$1; |
− | $stamp=$2; |
+ | $stamp=$2; |
− | $name =~ s/_.+//; |
+ | $name =~ s/_.+//; |
− | $age =($ctime - $stamp) / 60; |
+ | $age =($ctime - $stamp) / 60; |
− | if ($age < 10) { |
+ | if ($age < 10) { |
− | $table =~ s/_key//; |
+ | $table =~ s/_key//; |
− | print "$table\t $name\t $age\n"; |
+ | print "$table\t $name\t $age\n"; |
− | } |
+ | } |
− | } |
+ | } |
− | } |
+ | } |
− | } |
+ | } |
Revision as of 01:45, 7 June 2012
#!/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"; } } } }