Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to alert when Root Password Expiry in AIX

Tags:

shell

aix

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 .

like image 385
Deepesh Shetty Avatar asked Nov 11 '22 18:11

Deepesh Shetty


1 Answers

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.

like image 128
Nachiket Kate Avatar answered Dec 20 '22 02:12

Nachiket Kate