https证书过期时间查询脚本
file=$1 expire=$2 domain_list="list.txt" expire_result="info.log" function start() { rm -rf ./$expire_result ./$domain_list ./res_${file} } function get_domain() { suffix=$(cat $file | awk '{print $1}' | awk -F. '{print $(NF-1)}' | awk 'NR==1{print $1}') cat $file | egrep -v "^_" | awk '{print $1}' | sed "s/${suffix}./${suffix}/g" | sort -k2n | awk '{if ($0!=line) print;line=$0}' > list.txt } function get_expire() { log=./$expire_result for Domain in `cat $domain_list` do Port_List=`nmap -Pn -T 5 $Domain |grep -w "open" |awk -F'/' '{print $1}'` echo "--- $Domain ---" | tee >> $log echo "open port: `echo $Port_List`" | tee >> $log for Port in $Port_List do Info=`openssl s_client -servername $Domain -connect $Domain:$Port < /dev/null | openssl x509 -noout -dates -subject` #If SSL is not turned on, the loop exits if [ -z "$Info" ] then echo "Port $Port SSL is not enabled" | tee >> $log continue else echo "Port $Port SSL is enabled" | tee >> $log fi StartTime=`echo $Info| awk -F'=' '{print $2}'|awk '{$NF="";print $0}'|xargs -I {} date '+%Y-%m-%d' --date {}` EndTime=`echo $Info | awk -F'=' '{print $3}'|awk '{$NF="";print $0}'| xargs -I {} date '+%Y-%m-%d' --date {}` Domain_Name=`echo $Info | awk -F'=' '{print $5}'` echo " $Domain:$Port SSL domain: $Domain_Name" | tee >> $log echo " $Domain:$Port SSL StartTime: $StartTime" | tee >> $log echo " $Domain:$Port SSL EndTime: $EndTime" | tee >> $log done done } function get_ip() { for domain in `cat ./$expire_result | grep "EndTime: $expire" | awk '{print $1}' | awk -F: '{print $1}'` do while read line do echo $line | grep $domain if [ $? -eq 0 ];then ip=$(echo $line | awk '{print $5}') cat res_${file} | grep $ip if [ $? -ne 0 ];then echo $ip >> res_${file} fi fi done < $file done } #function get_result() { # sort -k2n res_${file} | awk '{if ($0!=line) print;line=$0}' > ip_${file} #} start get_domain get_expire get_ip