Thursday, January 31, 2019

Python script for checking linux user account and password expiry

Advertisements

We create many local users in linux systems. If it is a production system, we usually set expiry dates for accounts and passwords. Usually we set these things and forget about this. And when application fails because of user or password expiry we think about it again. If would be great if we get some alert before user account or password expiry. Isn't it?


How can we achieve this? We can do this by using a simple python script with nrpe(nagios)

We will create the script which will take all the local users from the /etc/passwd file, check their account and password expiry and show warning if the expiry dates are less than the specified argument.

Source code can be found in github. Python script to check linux user account and password expiry

The logic is to run the linux command chage for each user and get the details from the chage output for each user. If the expiry of any user is within the warning condition, show the username with warning.

No comments:

Post a Comment

Be nice. That's all.