From PRAGMAgridWIKI
#!/bin/bash
setDefaults()
{
certsDir="/etc/grid-security/certificates"
currentTime=`date +%s`
factor=86400
}
findDaysLeft()
{
certTime=`date --date="$T" +%s`
difference=$(($certTime - $currentTime))
daysLeft=$(echo "scale=1; $difference / $factor" | bc)
}
checkCrls()
{
crls=`ls $certsDir/*.r0`
for file in $crls
do
T=`grep "Next Update:" $file | sed -e 's/^ *Next Update: //'`
findDaysLeft $T
CA=`openssl crl -issuer -in $file -noout | sed -e 's/issuer=//'`
echo "$daysLeft days $file"
done
}
checkCerts()
{
certs=`ls $certsDir/*.0`
for file in $certs
do
T=`grid-cert-info -ed -f $file`
findDaysLeft $T
echo "$daysLeft days $file"
done
}
printHelp()
{
# print help
echo "Usage: $0 {-r|-c}" 1>&2
echo "For each certificate or crl file prints the file name and the"
echo "the number of days left before the certificate or crl expires."
echo "Uses a default location /etc/grid-security/certificates/ for "
echo "certificates and crls."
echo " -r check crl files "
echo " -c check certificate files"
echo
}
# parse command line arguments
case $1 in
-r)
setDefaults
checkCrls | sort -n -r
;;
-c)
setDefaults
checkCerts | sort -n -r
;;
*)
printHelp
exit 1
;;
esac