首页 > 解决方案 > 如何将动态日期戳添加到由 Bash cron 发送的 JSON 有效负载?

问题描述

我有一个 .sh 脚本,它将由 cron 每天执行一次,它将发送一个 curl 请求,如下所示:

curl -u username_here --header "Content-Type: application/json" --data @JSON_FILE_NAME_HERE "http://URL_LISTED_HERE"

json 文件包含以下示例数据:

{
    "name" : "TEST",
    "start_date" : "2021-03-22T13:00:00.000Z",
    "end_date" : "2021-03-22T00:45:00.000Z",
    "operators" : "OR",
    "recurrence" : "",
    "user" : "username_here",
    "subsets" : [
        {
            "subset1" : [
                "hostname",
                "isoneof",
                [
                    "test1.com",
                    "test2.com",
                    "test3.com"
                ]
            ]
        }
    ]
}

有没有办法让 'start_date' 和 'end_date' 在 cron 运行时自动生成,所以 'start_date' 是当前时间,而 'end_date' 是从当前时间开始的一小时?

标签: jsonbashdatecron

解决方案


推荐阅读