1834552 Members
3522 Online
110069 Solutions
New Discussion

Re: User maintenance

 
Sailesh_1
Advisor

User maintenance

Hi,

I have users created on a trusted system with expire date set.everything is going well.users are deactivated on their expiry date set. then I have to delete them manually from the system.

Now, I need to know is there any way, I can automate the user deletion process.i.e, once the user is expired, then delete the user from the system.

Please let me know is there any way to do it..may be a script could do it..

Thanks,
Sailesh

6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: User maintenance

userdel -r should do what you need. Man userdel for details. -r will delete their home diirectory (and subdirectories) BUT if this user owns files anywhere else they are left in place. A simple find /dir1 /dir2 -user user -exec rm {} \; would take take of those BUT this could be dangerous if any files were used by other processes/users. The same could apply to files in the user's home directory. That is why this is typically a manual process. If you KNOW that it is safe to remove all the files in the user's home directory then userdel -r is your boy.

If it ain't broke, I can fix that.
Todd McDaniel_1
Honored Contributor

Re: User maintenance

Sailesh,

You can use the directory creation date for their home directory as the timer to check against.

Just write a script to check versus that date and store the value in a variable per user or a file per user.

If your expiration timer is 30 days. write a script to check once a day at midnite or early morning to see if the date. As they reach the deadline then the script will spawn run: userdel -r $USERNAME
Unix, the other white meat.
Sailesh_1
Advisor

Re: User maintenance

I'm sorry if my question is not clear..
When I say I'm deleting the users manually, I'm using "userdel -r".

I need to know some method (useradd option or a script) to permenantly delete the user accounts from the unix box once the user account is expired.

Thanks,
Sailesh
Todd McDaniel_1
Honored Contributor

Re: User maintenance

Correct me if im wrong but userdel -r removes all traces of hte user, including removing them from the /etc/passwd file.

I just tested it and it works...
Unix, the other white meat.
John Kittel
Trusted Contributor

Re: User maintenance

Sailesh,

As the others have already suggested, of course, put userdel -r command inside your script...

but, what I wanted to add, regarding how the script can detect expired users, I think you could use the command,

"logins -a -l
perhaps more straightforward than looking at their home dir creation date.

- John
John Kittel
Trusted Contributor

Re: User maintenance

I meant,

logins -a -l



- John