Command Line Last 5 Minutes

Query shared by Rick Jerz on Moodle forums.

Turned it into a bash shell script so when working from command line one can see how many users are logged onto moodle during the last 5 minutes.

Called ‘last5′ … here’s the contents (all on one line – you sub the [USER] [PASSWD] and [DBNAME] below:

mysql -u [USER] -p'[PASSWD]’ -e “use [DBNAME];SELECT firstname,lastname,lastip,from_unixtime(lastaccess) as LastClick,now()-interval 5 minute as Last5Minutes FROM mdl_user having LastClick > Last5Minutes order by lastaccess desc;”> last5.txt;cat last5.txt

Outputs something like:

firstname lastname lastip LastClick Last5Minutes
Ken Task x.x.x.x 2018-08-23 19:20:00 2018-08-23 19:16:10

 

Leave a Reply