Need to get mail , in advance of approx one week if password suppose to be expire

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Need to get mail , in advance of approx one week if password suppose to be expire
# 1  
Old 03-31-2020
Need to get mail , in advance of approx one week if password suppose to be expire

I am preparing script , if user's password needs to be expire in one week. script is running, but gives output in 0.
please help, if any one worked on it..

User details.

[root@localhost ~]# chage  -l natasha
Last password change                                    : Feb 09, 2020
Password expires                                        : Apr 01, 2020
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 40
Maximum number of days between password change          : 52
Number of days of warning before password expires       : 7

script -------
SUBJECT="Information About User Password Expiration on "`date`""
echo "-------------------------------------------------" >> $MESSAGE1
echo "UserName  The number of days the password expires" >> $MESSAGE1
echo "-------------------------------------------------" >> $MESSAGE1
for usern in natasha
today=$(date +%s)
userexpdate=$(chage -l $usern | grep 'Password expires' |cut -d: -f2)
passexp=$(date -d "$userexpdate" "+%s")
exp=`expr \( $passexp - $today \)`
expday=`expr \( $exp / 86400 \)`
echo "$usern $expday" >> $MESSAGE
cat $MESSAGE | awk '$2 <= 10' >> $MESSAGE1
mail -s "$SUBJECT" "$TO" < $MESSAGE1


root@localhost ~]# cat /tmp/user-expiry-1.txt
natasha 0
natasha 0
natasha 0
UserName  The number of days the password expires
natasha 0
natasha 0
natasha 0
natasha 0

Last edited by vbe; 03-31-2020 at 12:16 PM.. Reason: code tags
# 2  
Old 03-31-2020
Please tell us all which operating system you are working on and its version number.
# 3  
Old 04-01-2020
This is rhel 7.7
# 4  
Old 04-01-2020
Is there any idea ? how to get the notification.
# 5  
Old 04-02-2020
I'm a bit surprised about your output - how come it containes seven lines "natasha 0" when looping across one single username only? And three lines of those above the header lines? Sure the tmp files are empty when running the script? What be the values of the variables (userexpdate, passexp, exp, expday) during the one loop? Run script with the -x option set, and post output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need in for a script that should check for errors in multiple log file (approx 2500) and should mail

hello everyone, I am new to linux and got this deliverable to write a script that should check for error in multiple log file (count is approx 2500 log files on single server) and once error is found, it should mail that error My logic says: we can put all log files path/location in one... (2 Replies)
Discussion started by: Pratik_CTS
2 Replies

2. Solaris

Force to reset password after expire

Hi Lads, I would like place the mechanism of force reset password to user when he login to the server after his password expired. Currently, We are resetting users once in every 60 days using cron job but I am thinking is there any other way to force reset passwords after it expires? I am using... (1 Reply)
Discussion started by: Navkreddy
1 Replies

3. AIX

Password Expire Message

Does anyone know if the default message displayed when a users password has expired can be changed? I am just assuming the message below is the default one. If so please tell. Using username "justinxx". justinxx@'s password: WARNING: Your password has expired. You must... (2 Replies)
Discussion started by: juredd1
2 Replies

4. UNIX for Advanced & Expert Users

SFTP password expire error

Hi, I am using sftp in batch script for which all configuration for public/private keys are done and it works fine without asking a password. No issues till this point. Now I the problem I have is that if the password expires/someone changes the authentication keys at reote server then the... (4 Replies)
Discussion started by: coolwade
4 Replies

5. Solaris

Problem with password expire and sudo.

Hi, I have a small problem that I need to address regarding the password expiration for a number of different oracle accounts. Currently I have the MAXWEEKS set to 12 in the /etc/default/passwd file for all accounts. I also have sudo installed on the server and users access the oracle accounts... (2 Replies)
Discussion started by: sparcman
2 Replies

6. Red Hat

set password not to expire

Hi All, Is this true on chage command? -M, MAX_DAYS Passing the number -1 as MAX_DAYS will remove checking a password's validity. Does this means password will not expire anymore? Thanks for any comment you may add. (0 Replies)
Discussion started by: itik
0 Replies

7. Solaris

Set Password Never Expire

Hello I want to set the password for user never expire through the command line. For your information the box is running under Solaris 8 platform. (2 Replies)
Discussion started by: shamsul
2 Replies

8. Shell Programming and Scripting

Password expire

Hi, Is there any way to find out the UNIX user's password expire date?. It'll we helpful to inform the users to change the password before it get expires.(FYI - I am not having only admin previlege.) (1 Reply)
Discussion started by: sharif
1 Replies

9. UNIX for Advanced & Expert Users

Disable password expire in HP UNIX

Hi, How to disable passwd expire in HP UNIX by not using SAM ? In our system SAM have some strange bugs. However due to some reason, we cannot add that patch. B. Rgds Christina (3 Replies)
Discussion started by: christina fung
3 Replies

10. UNIX for Advanced & Expert Users

password will expire

login: TEST7 TEST7's Password: Your password will expire: Wed Feb 19 14:28:08 2003 How can I the same information become in a script (as example in the .profile)????????? My login starts with .profile. These File is a menue with 24 lines and the message " Your password ....." disappear to... (8 Replies)
Discussion started by: Erwin Stocker
8 Replies
Login or Register to Ask a Question

Featured Tech Videos