last - find out inactivity


 
Thread Tools Search this Thread
Operating Systems AIX last - find out inactivity
# 1  
Old 07-25-2012
last - find out inactivity

I am on AIX 6.1, and need to find out who has not accessed the system within 1, 2, or 3 months depending upon the filter I specify.

The output I need to have is the account name and the last time accessed:

i.e.

kart Mar 27 05:13 - 05:13 (00:00)

Please advise.
# 2  
Old 07-25-2012
Here's a similar post of someone asking the same thing. Maybe it will help.
https://www.unix.com/unix-dummies-que...rs-logged.html
# 3  
Old 07-25-2012
HTML Code:
lsuser -a time_last_login ALL
doesn't show the last login time for all users. How do you convert epoch to human readable date for the ones showing up?

Please advise.
# 4  
Old 07-25-2012
I had this same requirement once so I through the below script together to get the output I needed.

Code:
#!/bin/ksh
#
# showlast.ksh
#
# show users that have logged X months ago

# define months
set -A months Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

# check command line for number of months
if [ "$#" -ne 1 ]
then
    echo "Usage: ${0##*/} <num of months>"
    exit 1
fi

# set the current month
cur_month=$(date '+%m')

# store the month from the command line
month_num=$1

# remove the zero padding if present
srch_month=$(echo $month_num|sed 's/0//')

# subtract the number of months from the current
# month
get_month=$(expr $cur_month - $srch_month)

# get month name from array by subtracting one from
# the number of months to match the correct array indice
month_index=$(expr $get_month - 1)
month_name=${months[$month_index]}

# call the last command and display the given number of
# months ago from current month
clear
echo "Logins From $month_num Months Ago"
echo
last | egrep $month_name | awk '!_[$1]++' | egrep -v 'reboot|shutdown' | sort -k1
echo

# done
exit 0

Running the script:
./showlast.ksh 2

Logins From 2 Months Ago

user1      pts/1        x.x.x.x                May 31 15:08 - 15:33  (00:25)
user2      rsh852070    x.x.x.x                May 31 15:17 - 15:17  (00:00)
user3      pts/1        x.x.x.x                May 31 14:54 - 15:07  (00:12)
user4      pts/0        x.x.x.x        	       May 21 17:22 - 17:49  (00:26)

Hope this helps.
# 5  
Old 07-25-2012
That looks great! But, I need to find out who has **NOT** accessed the system within 1, 2, or 3 months.
Please advise.
# 6  
Old 07-26-2012
Ok, try this one on for size... ;-)

Code:
#!/bin/ksh
#
# showlast
#
# show users that have logged X months ago

# define months
set -A months Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

# get list of users
tmpfile="/tmp/showlast.tmp"

# check command line for number of months
if [ "$#" -ne 1 ]
then
    echo "Usage: ${0##*/} <num of months>"
    exit 1
fi

# set the current month
cur_month=$(date '+%m')

# store the month from the command line
month_num=$1

# remove the zero padding if present
srch_month=$(echo $month_num|sed 's/0//')

# subtract the number of months from the current
# month
get_month=$(expr $cur_month - $srch_month)

# get month name from array by subtracting one from
# the number of months to match the correct array indice
month_index=$(expr $get_month - 1)
month_name=${months[$month_index]}

# call the last command and display the given number of
# months ago from current month
clear
echo "Logins From $month_num Months Ago"
echo
last | egrep $month_name | awk '!_[$1]++' | egrep -v 'reboot|shutdown' | sort -k1
echo

# dump our users that have logged in within the given number
# of months to the temp file 
last | egrep $month_name | awk '!_[$1]++' | egrep -v 'reboot|shutdown' | sort -k1 > $tmpfile

# dump a list the user accounts (minus the system accounts) to an array
set -A userlist $(awk -F: '$1 ~ /bin|daemon|sys|adm|uucp|lp|lpd|invscout|snapp|nuucp|sshd|ipsec|radius/{next}{print $1}' /etc/passwd)

# store number of elements in userlist
num_of_users=${#userlist[@]}

# loop through the lastusers array and print users that have not 
# logged in during the given number of months
echo 
echo "Non-Active Users From $month_num Months Ago"
echo
count=0
usercount=0
while [ $count -lt $num_of_users ]
do
    match=$(grep -c ${userlist[$count]} $tmpfile)
    if [ $match -eq 0 ]
    then
        echo ${userlist[$count]}
    fi
    ((count=$count+1))
done
echo

# done
rm -f $tmpfile
exit 0

This User Gave Thanks to in2nix4life For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

User inactivity

Simple question: for determining whether the user has exceeded the maximum amount of "inactivity" (as set in the shadow file) what date is the current login being compared to? Is it wtmp data or something? (3 Replies)
Discussion started by: thmnetwork
3 Replies

2. Shell Programming and Scripting

Shell exit due to inactivity

I am installing an executable files. It takes around 30 minutes. During this time...the shell pops the msg "due to inactivity shell pops out in 60 seconds. I dont want this to happen. the terminal shouldnt exit at all. Is there any way that it doesnt exit.I am using putty with ksh (7 Replies)
Discussion started by: sriki32
7 Replies

3. UNIX for Dummies Questions & Answers

lock the console after 5 minutes of inactivity.

How would i force The server console to be locked automatically after 5 minutes ? I want it to happen for X as well as terminal session of the machine. My Linux distribution details. LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch Distributor ID:... (11 Replies)
Discussion started by: pinga123
11 Replies

4. IP Networking

TCP server dies after few hours of inactivity

We have a NAS application which can be accessed by both HTTP and HTTPS connections. The issue we are facing is that the tcp server instance that initiates the HTTP access dies after a few hours of inactivity(the NAS application was kept idle for around 10 hours). However, the tcpserver that... (1 Reply)
Discussion started by: swatidas11
1 Replies

5. Red Hat

inactivity default to 30 days

Hi All, On red hat ent 4. How do I make the inactivity a default to 30 days? What config file I need to modify so that I will not modify /etc/shadow? Thanks for any comment you may add. (1 Reply)
Discussion started by: itik
1 Replies

6. Solaris

solaris 9 console inactivity timeout

All, I log into Solaris 9 server through a command line at the console and want enable a inactivity timer to log out of the server after 5 minutes. How can it be done? (1 Reply)
Discussion started by: bubba112557
1 Replies

7. UNIX for Advanced & Expert Users

User inactivity at OS level

Dear friends, Can anyone let me know how to configure various OS mentioned below to get user ids deactivated automatically if not logged in at all for a period of, say, 45 days? 1. UNIX / Linux / AIX / Tru64 2. It is OK whether the solution is by running OS commands / running scripts written... (1 Reply)
Discussion started by: bache_gowda
1 Replies

8. SCO

Apparent logoff’s due to inactivity.

I have run across an issue with the last two Dell Poweredge servers I have attempted to deploy. I seems that when a telnet session sits idle for 5 to 30 minutes (seems random) the session is being closed and users are logged off. If the session has user activity there is no problem staying... (0 Replies)
Discussion started by: gadgetman
0 Replies
Login or Register to Ask a Question