I am trying to build a script in AIX which I am planing to run as cron job. I want the script to check if the root password will expire with in 10 days and trigger an email. I have written a script to trigger mail but I am not sure how to write a script for password expiry for root.
This is script for sending mail .
#!/bin/sh
sendmail -t -F 'ABC ' -f '[email protected]' << test.mail
From: ABC <[email protected]>
To: [email protected]
Subject:
Password expired in 10 days
This script works fine .
But i want a script for AIX that will check root password expiry within 10 days of expiry date .
you can do it like,
lastupdate=lssec -f /etc/security/passwd -a lastupdate -s <username> | cut -d " " -f2 |cut -d "=" -f2
maxage=lsuser -a maxage itimadm | cut -d " " -f2 |cut -d "=" -f2
maxage=$(($maxage*7))
expires=$(($lastupdate+(60*60*24*$maxage)))
expire_date=perl -le 'print scalar localtime $expires
daysremaining=ceil((($expires - $now) / (60*60*24)) - 1)
echo $username,$maxage,$expire_date,$daysremaining
Though this is not full fledged script but logic is present (improvement is possible :) ) and you can add if clause for checking condition (daysremaining<10) then call your mailing script which will send mail to respective users.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With