Find users in 24 hour | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Find users in 24 hour

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2013
learnbash learnbash is offline
Banned
 
Join Date: Mar 2008
Last Activity: 28 July 2014, 4:29 PM EDT
Posts: 364
Thanks: 31
Thanked 3 Times in 3 Posts
Find users in 24 hour

How can I find that time when maximum number of users were login in last 24 hours. We have 500 users in that server.

---------- Post updated at 02:13 PM ---------- Previous update was at 01:17 PM ----------

on particular date 26-march-2013. Just for example we want to trace in which timings maximum users were online.
Sponsored Links
    #2  
Old 03-26-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 November 2014, 4:51 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,526
Thanks: 8
Thanked 555 Times in 532 Posts
You could poll the line counts of 'who' with a simple script, looping and sleeping, with time and day-of-week from date '+$...'.
Sponsored Links
    #3  
Old 03-26-2013
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 November 2014, 10:23 PM EST
Posts: 3,027
Thanks: 114
Thanked 971 Times in 910 Posts
You could process the output of last -t looking for "gone - no logout" where users are in at a particular time:

Here is split that day up into 5min blocks and check each block:


Code:
STS=$(date -d "$*" +%s)
INC=0
MAX=0
while [ $INC -lt $((60*60*24)) ]
do
   CNT=$(last -t $(date -d @$((STS+INC)) +%Y%m%d%H%M%S) | grep "gone" | wc -l)
   if [ $CNT -gt $MAX ]
   then
       MTIME=$((STS+INC))
       MAX=$CNT
   fi
   let INC=INC+5*60
done

echo "Maximum users: $MAX at $(date -d @$MTIME)"

Call it like this:


Code:
$ max_user.sh 26 Mar 2013
Maximum users: 4 at Tue Mar 26 15:05:00 EST 2013

---------- Post updated at 08:37 AM ---------- Previous update was at 08:26 AM ----------

Note: this is very dependent on your last -t command output under Fedora I get something like this, which is what I developed/tested with:


Code:
last -t 20120727163900
chubler  pts/1        192.168.1.3      Fri Jul 27 16:38    gone - no logout 
chubler  pts/1        192.168.1.3      Fri Jul 27 16:38 - 16:38  (00:00)    
chubler  pts/1        192.168.1.3      Fri Jul 27 16:36 - 16:36  (00:00)    
chubler  pts/1        192.168.1.3      Fri Jul 27 16:34 - 16:34  (00:00)    
chubler  pts/0        :0               Fri Jul 27 16:25    gone - no logout 
chubler  :0           :0               Fri Jul 27 16:14    gone - no logout

    #4  
Old 03-27-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 November 2014, 4:51 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,526
Thanks: 8
Thanked 555 Times in 532 Posts
I noticed that who missed my terminals, so I went to counting tty's:
Code:
$ ps -el|awk '{print $12}'|sort -u|egrep -vc '\?|TTY|console'
12
$

Collect the data maybe put it in an RDBMS, as you can expect they will want to know when/what is the low, what is the trend, ....
Sponsored Links
    #5  
Old 03-27-2013
verdepollo's Avatar
verdepollo verdepollo is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 7 November 2014, 1:54 AM EST
Location: Mexico
Posts: 725
Thanks: 11
Thanked 106 Times in 102 Posts
There's a Munin plugin named "logins" that does exactly that. Plus it already draws a nice and clean graph. Here's a live demo:

Munin :: munin-monitoring.org :: demo.munin-monitoring.org :: users
Sponsored Links
    #6  
Old 03-27-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 November 2014, 4:51 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,526
Thanks: 8
Thanked 555 Times in 532 Posts
Yes, in the Internet age, Googling skills are most important, after the imagination that says there might already be! It's not what you know any more!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find files modified in last hour sunOS 5.10 rich@ardz Shell Programming and Scripting 19 07-15-2010 03:43 AM
perl find directory only if modified in last hour frustrated1 Shell Programming and Scripting 0 10-12-2007 05:50 PM



All times are GMT -4. The time now is 03:25 PM.