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
CHAGE(1)                                                           User Commands                                                          CHAGE(1)

NAME
chage - change user password expiry information SYNOPSIS
chage [options] LOGIN DESCRIPTION
The chage command changes the number of days between password changes and the date of the last password change. This information is used by the system to determine when a user must change his/her password. OPTIONS
The options which apply to the chage command are: -d, --lastday LAST_DAY Set the number of days since January 1st, 1970 when the password was last changed. The date may also be expressed in the format YYYY-MM-DD (or the format more commonly used in your area). -E, --expiredate EXPIRE_DATE Set the date or number of days since January 1, 1970 on which the user's account will no longer be accessible. The date may also be expressed in the format YYYY-MM-DD (or the format more commonly used in your area). A user whose account is locked must contact the system administrator before being able to use the system again. Passing the number -1 as the EXPIRE_DATE will remove an account expiration date. -h, --help Display help message and exit. -I, --inactive INACTIVE Set the number of days of inactivity after a password has expired before the account is locked. The INACTIVE option is the number of days of inactivity. A user whose account is locked must contact the system administrator before being able to use the system again. Passing the number -1 as the INACTIVE will remove an account's inactivity. -l, --list Show account aging information. -m, --mindays MIN_DAYS Set the minimum number of days between password changes to MIN_DAYS. A value of zero for this field indicates that the user may change his/her password at any time. -M, --maxdays MAX_DAYS Set the maximum number of days during which a password is valid. When MAX_DAYS plus LAST_DAY is less than the current day, the user will be required to change his/her password before being able to use his/her account. This occurrence can be planned for in advance by use of the -W option, which provides the user with advance warning. Passing the number -1 as MAX_DAYS will remove checking a password's validity. -R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. -W, --warndays WARN_DAYS Set the number of days of warning before a password change is required. The WARN_DAYS option is the number of days prior to the password expiring that a user will be warned his/her password is about to expire. If none of the options are selected, chage operates in an interactive fashion, prompting the user with the current values for all of the fields. Enter the new value to change the field, or leave the line blank to use the current value. The current value is displayed between a pair of [ ] marks. NOTE
The chage program requires a shadow password file to be available. The chage command is restricted to the root user, except for the -l option, which may be used by an unprivileged user to determine when his/her password or account is due to expire. CONFIGURATION
The following configuration variables in /etc/login.defs change the behavior of this tool: FILES
/etc/passwd User account information. /etc/shadow Secure user account information. EXIT VALUES
The chage command exits with the following values: 0 success 1 permission denied 2 invalid command syntax 15 can't find the shadow password file SEE ALSO
passwd(5), shadow(5). shadow-utils 4.5 01/25/2018 CHAGE(1)
All times are GMT -4. The time now is 01:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy