英文:
Using current timestamp at command line
问题
我有这个按预期工作的命令:
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()?
英文:
I have this command that works as expected:
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 \
But I wish I could write something like this...
    --start-time now() - 12 hours \
    --end-time now() \
Is it possible to use now() in shell?
答案1
得分: 2
你可以按照以下方式使用它:
    --start-time $(date -u -d '12小时前' +%Y-%m-%dT%H:%M:%SZ) \
    --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
希望这对你有帮助。
英文:
You can use it in following way
    --start-time $(date -u -d '12 hour ago' +%Y-%m-%dT%H:%M:%SZ) \
    --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
Hope this helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论