Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created June 7, 2016 16:11
Show Gist options
  • Select an option

  • Save sonsongithub/07ac934fe7c23b796fcb3cbd28cef91b to your computer and use it in GitHub Desktop.

Select an option

Save sonsongithub/07ac934fe7c23b796fcb3cbd28cef91b to your computer and use it in GitHub Desktop.
SSLの証明書の期限をJSONで書き出すコード
require 'json'
require 'date'
r = []
hosts = []
hosts.each{|host|
if`sudo openssl x509 -in /etc/letsencrypt/live/#{host}/fullchain.pem -noout -dates` =~ /notAfter=(.+?)$/
entry = {}
entry[:host] = host
entry[:expireDate] = $1
expireDate = Date.parse($1)
today = Date::today
entry[:remainingDays] = (expireDate - today).to_i
r.push(entry)
end
}
json = {}
json[:data] = r
json[:lastUpdate] = Time.now.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment