Solved

How to list Inactive user account (AIX, SOLARIS, LINUX)

Posted on 2011-09-14
3
2,949 Views
Last Modified: 2013-12-04
Hi I need to find and list all inactive user account (45 days without logging) on aix, solaris and linux.

I have to disable all the inactive account.
0
Comment
Question by:cismoney
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 36535365
Hi,

the attached script should give you a start for AIX.

It lists how many days ago your users last logged in.

Please note that the script doesn't list users without a password (they cannot login anyway),
users with a userid less than 12 (those system-related ids should not be touched),
and the userid "nobody" (needed for several system purposes, e.g. lpd).

Have fun!

wmp
awk -F: '$2!="*"&&$3>11&&$1!="nobody" {print $1}' /etc/passwd |\
xargs -I{} lssec -f /etc/security/lastlog -s {} -a time_last_login 2>/dev/null |\
awk -v N=$(date +%s) -F" |=" '
 {if($3!="") {printf "%16s\t%s %.1f %s\n", $1, "last login", (N-$3)/(3600*24), "days ago"}
   else printf "%16s\t%s\n", $1, "never logged in"}' |sort -k2

Open in new window

0
 

Author Comment

by:cismoney
ID: 36535453
thanx WMP,

the script is  .sh ?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36535461
It works with sh, ksh and bash
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now