LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-29-2013, 03:35 AM   #1
getraj.12
LQ Newbie
 
Registered: Jul 2010
Location: Bangalore, India
Distribution: RedHat, Suse, Solaris
Posts: 15

Rep: Reputation: 0
Shell Script to extract User account expiry details


Hello Experts,

Does any one have a working shell script which extracts the user account expiry details and password expiry details and logs the info to a file ?

we can use "chage" to get the user account expiry details in linux. I want to ignore the system user IDs from passwd file and also if the account expiry is set to never, i need to ignore those ids as well.

Appreciate your prompt response...
 
Old 04-29-2013, 04:39 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Well the prompt response would be, what have you done and where are you stuck? We are not here to do your work for you.
 
Old 04-29-2013, 10:46 AM   #3
getraj.12
LQ Newbie
 
Registered: Jul 2010
Location: Bangalore, India
Distribution: RedHat, Suse, Solaris
Posts: 15

Original Poster
Rep: Reputation: 0
@ Grail
I have already worked on a small script to run on both solaris and Linux to find the locked users. But now I need to include account expiry and passwd expiry details which will log the details in a file. In case of Linux we can use chage cmd to ge these details but im struck up in finding a way to log only the accounts which has any expiry dates set and ignore if the expiry is set to "never" and log only if the expire field has some dates in it.

Could you pls suggest me any ideas for the same ?


OS=`uname -s`

case "$OS" in

SunOS)
cat /etc/passwd | awk -F: '{print $1}' > /tmp/users
cat /tmp/users | while read line; do echo `passwd -s $line`; done|grep LK > /tmp/`hostname`.LOCKED
;;
Linux)
cat /etc/passwd | awk -F ":" '{print $1}' > /tmp/users
cat /tmp/users | while read line; do echo $line `passwd -S $line`; done|grep locked > /tmp/`hostname`.LOCKED
;;
 
Old 04-29-2013, 11:46 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Well firstly, the repetition of code hardly seems necessary. I wuold guess there are better system admin ways to do this, but based on the current information, I would go with something like:
Code:
OS=$(uname -s)

case "$OS" in
  SunOS) locked=LK;;
  Linux) locked=locked;;
esac

while IFS=":" read -r name _
do
    passwd -S "$name" | grep "$locked"  > /tmp/$(hostname).LOCKED
    chage -l "$name" | grep -E '(Password|Account) expires' > /tmp/$(hostname).EXPIRED
done</etc/passwd
It may need some tweaking and not sure what shell you will be using, but you should get the idea.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LDAP Account Password Expiry Script Doknik Linux - Newbie 1 08-04-2011 04:36 AM
user account details ZAMO Linux - Enterprise 4 11-20-2008 06:22 AM
How to program shell script to automate mass user account creation? EsAsher Linux - General 2 06-30-2007 08:41 AM
Shell script for password expiry alert bhandu Linux - General 1 06-13-2007 04:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration