Root password expiry script

Hi Guys

In red hat linux server is there a way to alert via email when the root password is about to expire ?

As per security policy in our environment root password will expire in 90 days.

Example : It would be better if we receive a email on 7th november stating that the root password will expire on 14th november.
Any suggestions please..

There's a field in /etc/shadow which sets how many days before expiry the user is warned, however this warning is on logon and so will not work for rarely administered boxes.
chage -l root will give you this and other values including the expiry date of the current password.

Unfortunately the password expiry date is not in an easily calculable format, however it should be possible to convert it to epoch and compare with today's date, eg Perl's Date::Calc module provides a delta days function which could be used for this...

Delta_Days($year1,$month1,$day1,$year2,$month2,$day2); 

---------- Post updated at 11:59 ---------- Previous update was at 11:36 ----------

To expand...

perl  -e 'use Date::Calc qw(Delta_Days);
@today=(localtime(time))[3,4,5];
$expiry=qx(/usr/bin/chage -l);
%months=qw(Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12);
($expire_month, $expire_day,$expire_year)=$expiry=~/Password expires\s+:\s(\w+)\s(\d+),\s(\d+)/g;
$expire_month=$months{$expire_month};
$days_to_expiry=Delta_Days($today[2]+1900,$today[1]+1,$today[0],$expire_year,$expire_month, $expire_day);
if ($days_to_expiry < 7){
  use Mail::Sender;
  ...
}'