How to find how many users have logged in and logged out in last five minutes using shell scripts?

How many users have logged in and logged out in last five or 10 minutes

Questions by hankypanky

Showing Answers 1 - 11 of 11 Answers

Vijaymorey

  • Apr 28th, 2009
 

By writing "who -Hu" you get following details o/p

Name        Line           Time     Activity       PID Hostname

  Was this answer useful?  Yes

Indu Sharma

  • Jul 29th, 2011
 

Current_time=date +%H:%M
who -u | awk ' $4 - $Current_time == 5 {print } '

  Was this answer useful?  Yes

Disna

  • Jan 6th, 2012
 

last -5|grep -i "logged in"|wc -l
last -5|grep -v "logged out"|wc -l

  Was this answer useful?  Yes

sonia

  • Feb 19th, 2012
 

Current_time=`date +%H%M`
who -u | awk $Current_time - $4 <= 5 { print }

  Was this answer useful?  Yes

Ataul

  • May 21st, 2015
 

who | wc -l | last -5
#to get the counts of who are still logged in

  Was this answer useful?  Yes

sahilgaix

  • Oct 15th, 2015
 

# To find out who logged in/logged out in last 5 minutes(including who is currently logged in)
last|while read line
do
echo $line|grep "still logged in" > /dev/null
if [ $? -eq 0 ]
then
echo $line
else
login=`echo $line|awk {print $6}|sed s/://`
logout=`echo $line|awk {print $8}|sed s/://`
curtime=`date +%H%M`
if [[ `echo $line|awk {print $4 $5}` = `date|awk {print $2 $3}` ]]
then
if [ `echo "$curtime - $login"|bc` -le 5 -o `echo "$curtime - $logout"|bc` -le 5 ]
then echo $line
fi
fi
fi
done

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions