Calculate how many days remain on a remote TLS certificate
Build a paste-ready command, then review its compatibility and effects before running it.
end=$(openssl s_client -connect <host>:<port> -servername <host> </dev/null 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2); echo "notAfter=$end"; echo "daysRemaining=$(( ($(date -d "$end" +%s) - $(date +%s)) / 86400 ))"Complete required fields to copy the generated command.
Compatibility
GNU/LinuxUses GNU date -d. macOS requires a BSD date conversion or gdate from coreutils.
Operational knowledgereview due 2027-01-19
Requirementsendend must be installed and available on PATH.Network accessThe target must be reachable from the current environment.
Version supportend Current supported releasesVerified for linux using bash, zsh syntax; consult compatibility notes for platform-specific differences.
Expected signalsnotAfter=Oct 19 23:59:59 2026 GMTRepresentative successful output; values vary with the selected target and system state.
Known errorsend: command not foundend is missing or is not available on PATH.
Verifyend=$(openssl s_client -connect {{host}}:{{port}} -servername {{host}} </dev/null 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2); echo "notAfter=$end"; echo "daysRemaining=$(( ($(date -d "$end" +%s) - $(date +%s)) / 86400 ))"The output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01end=$(opensslVariable assignmentSets a value used by the commands that follow.
02s_clientCommandRuns the s_client stage of this one-liner.
03-connectOptionConfigures s_client with the -connect option.
04<host>:ParameterA value supplied in the Fill parameters section.
05<port>ParameterA value supplied in the Fill parameters section.
06-servernameOptionConfigures s_client with the -servername option.
07<host>ParameterA value supplied in the Fill parameters section.
08<RedirectionRedirects command input, standard output, or error output.
09/dev/nullArgumentPasses /dev/null to s_client.
102>RedirectionRedirects command input, standard output, or error output.
11/dev/nullArgumentPasses /dev/null to s_client.
12|PipelinePasses the output on the left to the command on the right.
13opensslCommandRuns the openssl stage of this one-liner.
14x509ArgumentPasses x509 to openssl.
15-nooutOptionConfigures openssl with the -noout option.
16-enddateOptionConfigures openssl with the -enddate option.
17|PipelinePasses the output on the left to the command on the right.
18cutCommandRuns the cut stage of this one-liner.
19-d=OptionConfigures cut with the -d= option.
20-f2)OptionConfigures cut with the -f2) option.
21;Command separatorEnds this shell statement before the next one begins.
22echoCommandRuns the echo stage of this one-liner.
23"notAfter=$end"ArgumentPasses "notAfter=$end" to echo.
24;Command separatorEnds this shell statement before the next one begins.
25echoCommandRuns the echo stage of this one-liner.
26"daysRemaining=$(( ($(date -d "ArgumentPasses "daysRemaining=$(( ($(date -d " to echo.
27$end"VariableExpands a value from the current shell environment or loop.
28+%s)OptionConfigures echo with the +%s) option.
29-OptionConfigures echo with the - option.
30$(dateVariableExpands a value from the current shell environment or loop.
31+%s))OptionConfigures echo with the +%s)) option.
32/ArgumentPasses / to echo.
3386400ArgumentPasses 86400 to echo.
34))"ArgumentPasses ))" to echo.
This advanced community-curated one-liner combines several stages. Review every option and placeholder before running it.
Example input
end=$(openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2); echo "notAfter=$end"; echo "daysRemaining=$(( ($(date -d "$end" +%s) - $(date +%s)) / 86400 ))"
Example output
notAfter=Oct 19 23:59:59 2026 GMT
daysRemaining=88
Illustrative output — exact values vary by system and data.
Official sources