在外壳中比较日期数字和输入数字

时间:2019-06-12 05:19:45

标签: php linux bash shell

www.google.com
current date: 2019-06-12 
exp date: 2019-08-14 
remaining: 63 
date mail select: 63 
not alert

问题是if语句的输出不能用作数学逻辑。 可能是$ diff的值和$ 2(input)不相等吗? 谁能告诉我如何确定它们?

#!/bin/bash

expi=$(echo | openssl s_client -servername $1 -connect $1:443 2>/dev/null | openssl x509 -noout -dates |grep "notAfter" | cut -d= -f2)

expi_date=$(date -d "$expi" +%Y-%m-%d)
current_date=$(date +%Y-%m-%d)

diff=$((($(date "+%s" -d "$expi_date")-$(date "+%s" -d "$current_date"))/86400))

echo $1

echo "current date: "$current_date

echo "exp date: "$expi_date

echo "remaining: "$diff

echo "date mail select: "$2

if [[$diff -eq $2]]
  then
    echo "alert"
  else
    echo "not alert"
fi

1 个答案:

答案 0 :(得分:0)

请参考以下代码:-

if [ "$diff" -eq "$2" ];
  then
    echo "equal"
  else
    echo "not equal"
fi