Sponsored Content
Top Forums Shell Programming and Scripting users who loged within 5 minutes Post 302125181 by aigles on Wednesday 4th of July 2007 09:28:50 AM
Old 07-04-2007
The who command gives time when the user logged in.
Code:
$ LANG=C who -s
gssjgu:/g/g00k00/gssjgu/TMP> LANG=C who -s
gssjgu      pts/1       Jul  4 15:06    (1.1.1.11)  
getk00      pts/2       Jul  4 08:54    (1.1.1.2)   
gti001      pts/3       Jun 22 15:38    (1.1.1.39)  
$

The following script display informations about users who logged in since n minutes (n can be specified as a parameter of the script, the defaut value is 5).
Code:
$ cat log5.sh
#!/usr/bin/ksh

typeset -i SINCE=${1:-5}

#
# Get current date
#

date '+%Y +%m %d %H %M' | read year month day hour min

#
# Compute timestamp for current date minus $SINCE minutes 
# format 'mmddHHMM' ('cal' command usage)
#

(( min  -= SINCE ))
(( min  <  0 )) && { (( min += 60 )) ; (( hour -= 1 )) }
(( hour <  0 )) && { (( hour += 24 )) ; (( day -= 1 )) }
(( day  <=  0 )) && { 
   (( month -= 1 ))
   (( month <= 0 )) && { (( month=12 )) ; (( year -= 1 )) }
   day=$(cal $month $year | tr '\n' ' ' | awk '{print $NF}')
}

ts5=$(printf "%02d%02d%02d%02d" $month $day $hour $min)   
#
# Determine users logged on since $SINCE minutes
# (Based on 'who -s' command)'
#

LANG=C who -s |
awk -v ts5="$ts5" -F '[ \t:]*' '
   function to_timestamp(month, day, hour, min) {
      m = index("___,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec,", "," tolower(month) ",")/4;
      return sprintf("%02d%02d%02d%02d", m, day, hour, min);
   }
   to_timestamp($3, $4, $5, $6) >= ts5
'
$

Output:
Code:
$ LANG=C date
Wed Jul  4 15:22:04 DFT 2007
$ log5.sh
$ log5.sh 30
gssjgu      pts/1       Jul  4 15:06    (1.1.1.11)  
$

 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert minutes to hours, minutes, seconds

How would you convert lets say a 1000 minutes to hours, minutes, seconds (1 Reply)
Discussion started by: Vozx
1 Replies

2. Shell Programming and Scripting

list the names of users who logoff in last 4 minutes

i am new to unix shell program, please someone hint me how to get the names of users who make logouts in last 4 minutes? i dont need complete script, but only the guide (2 Replies)
Discussion started by: jax_anchal
2 Replies

3. Post Here to Contact Site Administrators and Moderators

Then user who loged in befor 5 minutes

hi i am a student, i want to know how to display the users who loged in before 5 minutes, in uinx pls reply me immediately (0 Replies)
Discussion started by: roshni
0 Replies

4. AIX

command to kill all loged in users

Guy's I'm looking for command to kill all the loged in users in AIX server Is there specific command can help us to kill any loged in users I have this command who -u it'll show me the process ID of all the users but I want command to kill all the users including to root without... (1 Reply)
Discussion started by: Mr.AIX
1 Replies

5. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

6. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies
sulog(4)							   File Formats 							  sulog(4)

NAME
sulog - su command log file SYNOPSIS
/var/adm/sulog DESCRIPTION
The sulog file is a record of all attempts by users on the system to execute the su(1M) command. Each time su(1M) is executed, an entry is added to the sulog file. Each entry in the sulog file is a single line of the form: SU date time result port user-newuser where date The month and date su(1M) was executed. date is displayed in the form mm/dd where mm is the month number and dd is the day number in the month. time The time su(1M) was executed. time is displayed in the form HH/MM where HH is the hour number (24 hour system) and MM is the minute number. result The result of the su(1M) command. A ` + ' sign is displayed in this field if the su attempt was successful; otherwise a ` - ' sign is displayed. port The name of the terminal device from which su(1M) was executed. user The user id of the user executing the su(1M) command. newuser The user id being switched to with su(1M). EXAMPLES
Example 1: A sample sulog file. Here is a sample sulog file: SU 02/25 09:29 + console root-sys SU 02/25 09:32 + pts/3 user1-root SU 03/02 08:03 + pts/5 user1-root SU 03/03 08:19 + pts/5 user1-root SU 03/09 14:24 - pts/5 guest3-root SU 03/09 14:24 - pts/5 guest3-root SU 03/14 08:31 + pts/4 user1-root FILES
/var/adm/sulog su log file /etc/default/su contains the default location of sulog SEE ALSO
su(1M) SunOS 5.10 6 Jun 1994 sulog(4)
All times are GMT -4. The time now is 06:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy