php - 比较日期数字和 shell 中输入的数字

标签 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

最佳答案

请引用以下代码:-

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

关于php - 比较日期数字和 shell 中输入的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56555115/

相关文章:

php - 如何使用 Symfony ACL 过滤我的 Doctrine 查询

php - 使用 mqtranslate plus 在 wordpress 上翻译菜单上的自定义链接

linux - ubuntu 参数如何通过 uuidgen 去除 "-"格式

linux - SAP Netweaver 7.51 安装失败(NPL 安装失败...)

linux - 在 bash 中使用 read 和 Expect 自动响应

php - SQL时区问题

PHP session 在 Android 中不起作用?

php - 如何将 MySQL 远程数据库表插入本地数据库表?

python - 如何在shell脚本中修改rc.local?

bash - 嵌入在 bash 中的 Python 不工作