Sponsored Content
Operating Systems Linux Red Hat Problem with Script to email Admin users with expired passwords writed byygemici Post 302923053 by redmansas on Thursday 30th of October 2014 05:47:39 AM
Old 10-30-2014
RedHat Problem with Script to email Admin users with expired passwords writed byygemici

Hi,
I have problem with a script, it was working for 6 month and suddenly I started getting strange expire times
example:
Code:
[root@XXXXX passexp]# chage -l wXXp
Last password change                                    : Oct 28, 2014
Password expires                                        : Nov 27, 2014
Password inactive                                       : Nov 27, 2014
Account expires                                         : Nov 27, 2014
Minimum number of days between password change          : 0
Maximum number of days between password change          : 30
Number of days of warning before password expires       : 1

Code:
[root@XXXXX passexp]# ./passexp.sh wXXp root@XXXXX.localdomain 1
date: option requires an argument -- 'd'
Try `date --help' for more information.
Password Expired for wXXp user for '-16373' day(s).

And the script:
Code:
# cat check_passwd_expiry.sh
#!/bin/bash
## @ygemici unix.com simple password expire check script
## e.g -> "./passwordcheck.sh 'user' mailaddress" 'IFEXPDAYS[optional]'
## IFEXPDAYS if you specify interval day(s) for send to mail
## for ex -> IFEXPDAYS=100 means compare expire days if is it [1-100] then it sends e-mail
param_check() {
id $1 &>/dev/null
if [ ! $? -eq 0 ]; then
echo "No such user" ; exit 1;fi
if [[ ! $(echo "$2"|grep -o '.*@.*\..*') ]];then
echo "Check your e-mail address!!";exit 1;fi
}
param_check $1 $2
check() {
expirestatus=$(chage -l $1|awk -F'[: ]' '/Password expires/{print $4}')
[[ "$expirestatus" == "never" ]] && echo -e "Password expire status is NEVER for '$1' user.\nNo Send to Mail!!"&&exit
}
check $1
doit() {
expiretime=$(date '+%s' -d $(chage -l "$1"|\
awk -F: '/Password expires/{print $2}'|\
awk 'BEGIN{ORS="=";;m="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Dec"};
{sub(",","",$2);split(m,a);for(i=1;i<=12;i++)if(a[i]==$1)printf "%02s/%s/%s",i,$2,$3}'))
expl=$(awk -vnow=$(date '+%s') -vexpt=$expiretime 'BEGIN{print int((expt-now)/60/60/24)}')
mailaddr="$2"
if [[ $(echo "$expl"|grep '-') ]]; then
message="Password Expired for $1 user for '$expl' day(s)"
echo -e "$message.\nAn e-mail sent to '$2' for this information."
echo "Haslo wygasa za  '$expl' dni dla uzytkownika '$1'."|mail -s "Password Expired" "$mailaddr"
exit;fi
if [ ! -z "$3" ]; then
awk -ve=$expl -vi=$3 'BEGIN{if(e<i&&e>1){
print "An e-mail (Password Expiration WARNING!!) sent to ( '$mailaddr' )..";
system("echo \"Please change your password within the next in '$expl' days\" |mail -s \"Password Expire Notification\" '$mailaddr'")}}'
else
echo -e "Haslo wygasa za  '$expl' dni dla uzytkownika '$1'.\nNo Send to Mail!!"
fi
}
doit $1 "$2" $3

Thx for help
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Admin of Users from command line

I have been adding new users on a system(SOLARIS 8), and one of these 'nice'(?) users has got back to me to complain that his full name isnt showing up when he does the following at the command prompt : $ finger <login_id> You see when I added the users details at the command line using... (2 Replies)
Discussion started by: Kanu77
2 Replies

2. UNIX for Advanced & Expert Users

Changing Users Passwords Via Script?

I am the administrator for a large network of HP/UX servers, about 100, this will be growing to over 200 in the next 18 months, part of my duties are to change the root passwords on these machines once month... which is a pain. I have written a script that will generate random passwords for me and... (3 Replies)
Discussion started by: PJolliffe
3 Replies

3. UNIX for Dummies Questions & Answers

su - user... how to find out the list of users and their passwords..

hi, to do a su - user, we need to know what are the users... so in unix 1) which file to see the list of users, passwords? (2 Replies)
Discussion started by: yls177
2 Replies

4. AIX

script for finding all the users with GID 0 ( admin group )

Hi Friends, I am trying to write a script for finding all the users with the GID 0 i.e. Admin users. can you please help me on this. (1 Reply)
Discussion started by: anoopraok
1 Replies

5. AIX

AIX users got expired !

Guy's .. I have faced an issue in AIX server, users got expired without asking me about the expiration and did not asking me to change the old password moreover will not accept my login with old password any more until reset the ID with new password Pls assist in this to how configure the... (3 Replies)
Discussion started by: Mr.AIX
3 Replies

6. Solaris

To restrict the users not to change the passwords for NIS users

Hi All, How to restrict the NIS users not to change their passwords in for NIS users?? and my NIS user is unable to login to at client location what could be the problem for this ? Any body can help me. Thanks in advance. (1 Reply)
Discussion started by: Sharath Kumar
1 Replies

7. UNIX for Advanced & Expert Users

check for users blank passwords

Hello, I have an AIX 5.3 system. I want to check users to see whether there are users with blank passwords but i would prefer to do that without checking /etc/passwd or /etc/security/passwd files. Also while i was searching the web for a solution i noticed that many people refer to /etc/shadow... (2 Replies)
Discussion started by: omonoiatis9
2 Replies

8. Shell Programming and Scripting

Script to Send Email to a user when an admin kills process

Can anyone create or give me a script that I can use to email a user automatically when I kill one of their processes? Or Can you give me a script to allow me to email a user (entering email manually) when a process is killed? Like showing what the PID was and a reason the admin killed it? Is... (2 Replies)
Discussion started by: JoeGazz84
2 Replies

9. Shell Programming and Scripting

Create multiple users with individual passwords to users

hi, i am new to shell scripts i write a shell script to create multiple users but i need to give passwords to that users while creating users, command to write this script (1 Reply)
Discussion started by: DONFOX
1 Replies

10. UNIX and Linux Applications

How to make ldappasswd use {SHA} instead of {SSHA} for users passwords in openldap?

Is it possible to use {SHA} with ldappasswd? I didn't find responsible option in manual page and doc (1 Reply)
Discussion started by: urello
1 Replies
lchage(1)						      General Commands Manual							 lchage(1)

NAME
lchage - Display or change user password policy SYNOPSIS
lchage [OPTION]... user DESCRIPTION
Displays or allows changing password policy of user. OPTIONS
-d, --date=days Set the date of last password change to days after Jan 1 1970. Set days to -1 to disable password expiration (i.e. to ignore --mindays, and --maxdays and related settings). Set days to 0 to enforce password change on next login. (This also disables password expiration until the password is changed.) -E, --expire=days Set the account expiration date to days after Jan 1 1970. Set days to -1 to disable account expiration. -i, --interactive Ask all questions when connecting to the user database, even if default answers are set up in libuser configuration. -I, --inactive=days Disable the account after days after password expires (after the user is required to change the password). Set days to -1 to keep the account enabled indefinitely after password expiration. -l, --list Only list current user's policy and make no changes. -m, --mindays=days Require at least days days between password changes. Set days to 0 or -1 to disable this requirement. If this value is larger than the value set by --maxdays, the user cannot change the pasword. -M, --maxdays=days Require changing the password after days since last password change. Set days to -1 to disable password expiration. -W, --warndays=days Start warning the user days before password expires (before the user is required to change the password). Set days to 0 or -1 to disable the warning. EXIT STATUS
The exit status is 0 on success, nonzero on error. NOTES
Note that "account expiration" (set by --expire) is distinct from "password expiration" (set by --maxdays). Account expiration happens on a fixed date regardless of password changes. Password expiration is relative to the date of last password change. libuser Nov 8 2012 lchage(1)
All times are GMT -4. The time now is 11:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy