Problem with Script to email Admin users with expired passwords writed byygemici


 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Problem with Script to email Admin users with expired passwords writed byygemici
# 1  
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
# 2  
Old 10-30-2014
There's two occurrences of date in your spaghetti above. One has the -d option. The error message indicates that the result of $(chage ... is empty. Try to analyze that command and its results - I can't.
# 3  
Old 10-30-2014
November is missing!

Try changing this
Code:
awk 'BEGIN{ORS="=";;m="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Dec"};

to this
Code:
awk 'BEGIN{ORS="=";;m="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"};

This User Gave Thanks to junior-helper For This Post:
# 4  
Old 11-04-2014
Thx for help I was looking at that script for two days and didn't saw it...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question