Who rated this post

cancel
Showing results for 
Search instead for 
Did you mean: 
Igor_Demchenko
Participant

I made this simple script for crontab. It may be usefull for you

#!/bin/sh
source /etc/profile.d/CP.sh

CERTIFICATE=`cpca_client lscert -stat Valid -dn <SubString>`

#get string with expiration date from certificate info
CERT_INFO=`cpca_client lscert -stat Valid -dn <SubString> | grep Not_After`

#make list with expiration date, month and year
EXPIRED=$(python -c "lst='$CERT_INFO'.split('Not_After:'); print(lst[1].split())")

#get expiration day
EXPIRED_DATE=$( python -c "print($EXPIRED[2])" )
#get expiration month
EXPIRED_MONTH=$( python -c "print($EXPIRED[1])" )
#get expiration year
EXPIRED_YEAR=$( python -c "print($EXPIRED[-1])" )

DIFF=$(python -c "from datetime import (date, datetime); print date(2023, datetime.strptime('$EXPIRED_MONTH','%b').month, 11).toordinal() - date.today().toordinal()")

if [ $DIFF -lt 30 ];
then
echo -e "Subject: CheckPoint VPN certificate expiration\r\n\r\nVPN certificate will be expired in $DIFF days.\r\n\n\n $CERTIFICATE.\r\n " | sendmail --domain=<domain name> -f <from_email> -v <to_email> --host=<smtp_server>
fi

View solution in original post

(2)
Who rated this post