shell 在命令行使用当前时间戳

gz5pxeao  于 2023-06-24  发布在  Shell
关注(0)|答案(1)|浏览(119)

我有这个命令,它按预期工作:

aws cloudwatch get-metric-statistics \
    --region ap-south-1 \
    --namespace AWS/RDS \
    --metric-name DBLoad  \
    --period 60 \
    --statistics Average \
    --start-time 2023-06-12T01:00:00Z \
    --end-time 2023-06-12T23:00:00Z \

但我希望我能写这样的东西...

--start-time now() - 12 hours \
    --end-time now() \

可以在shell中使用now()吗?

daupos2t

daupos2t1#

你可以按以下方式使用它

--start-time $(date -u -d '12 hour ago' +%Y-%m-%dT%H:%M:%SZ) \
    --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \

希望这能帮上忙。

相关问题