-2
我接近這..我需要得到日期數學釘下來,這是相當馬虎的權利 - 我知道。 :)Java - 批處理文件試圖找到證書即將過期使用keytool
REM this is using routines from: http://www.robvanderwoude.com/datetimentmath.php
:: Strip the day of the week from the current date
FOR %%A IN (%Date%) DO SET Today=%%A
:: Parse the date, prefix day and month with an extra leading zero
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
REM For European date format DD-MM-YYYY use SET Day=0%%A and SET Month=0%%B instead
SET Day=0%%B
SET Month=0%%A
SET Year=%%C
)
:: Remove excess leading zeroes
SET Day=%Day:~-2%
SET Month=%Month:~-2%
:: Display the results
SET Day
SET Month
SET Year
:: Convert to Julian date
CALL :JDate %Year% %Month% %Day%
:: Display the result
SET /A sdate=JDate
REM BECAUSE WE ARE POTENTIALLY GOING INTO MULTIPLE KEYSTORES FOR JAVA'S KEYTOOL, WE CAN JUST BY-PASS THE PASSWORD
ECHO.|"%JAVA_HOME%\bin\keytool" -list -v -alias "company.com" -keystore "%JAVA_HOME%\jre\lib\security\cacerts" > results.txt
FOR /F "tokens=1-15 delims= " %%a IN ('TYPE results.txt ^| FIND "until:" ') DO (
if %%k EQU Jan set mn=01
if %%k EQU Feb set mn=02
if %%k EQU Mar set mn=03
if %%k EQU Apr set mn=04
if %%k EQU May set mn=05
if %%k EQU Jun set mn=06
if %%k EQU Jul set mn=07
if %%k EQU Aug set mn=08
if %%k EQU Sep set mn=09
if %%k EQU Oct set mn=10
if %%k EQU Nov set mn=11
if %%k EQU Dec set mn=12
CALL :Jdatea %%o %mn% %%l
SET /A edate=JDatea
)
Set /A=Result==%eDate%-%sDate%
REM if less than 30 days, send an alert
if %Result% LSS 30 blat -f "[email protected]" -t "[email protected]" -server 1.2.3.4 -subject "certificate for %computername% is about to expire in less than 30 days!" -q
:JDate
:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Returns : Julian date
::
:: First strip leading zeroes
SET MM=%2
SET DD=%3
IF %MM:~0,1% EQU 0 SET MM=%MM:~1%
IF %DD:~0,1% EQU 0 SET DD=%DD:~1%
::
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
SET /A Month1 = (%MM% - 14)/12
SET /A Year1 = %1 + 4800
SET /A JDate = 1461 * (%Year1% + %Month1%)/4 + 367 * (%MM% - 2 -12 * %Month1%)/12 - (3 * ((%Year1% + %Month1% + 100)/100))/4 + %DD% - 32075
SET Month1=
SET Year1=
GOTO:EOF
:JDatea
:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Returns : Julian date
::
:: First strip leading zeroes
SET MM=%2
SET DD=%3
IF %MM:~0,1% EQU 0 SET MM=%MM:~1%
IF %DD:~0,1% EQU 0 SET DD=%DD:~1%
::
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
SET /A Month1 = (%MM% - 14)/12
SET /A Year1 = %1 + 4800
SET /A JDate = 1461 * (%Year1% + %Month1%)/4 + 367 * (%MM% - 2 -12 * %Month1%)/12 - (3 * ((%Year1% + %Month1% + 100)/100))/4 + %DD% - 32075
SET Month1=
SET Year1=
GOTO:EOF
PAUSE
謝謝!
你能運行Java程序呢?看看這個問題:http://stackoverflow.com/questions/9513257/checking-certificates-expiration-dates-in-java-keystore –
儘管我想運行一個Java程序,但我仍然使用Keytool並已經整理出如何使用Keytool來完成它,並且回答了我自己的帖子。 – Leptonator
請將您的答案作爲答案發布並接受,因此將此問題從「未解決的問題」隊列中刪除。 – Stephan