-1

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?

shantanuo
  • 31,689
  • 78
  • 245
  • 403
  • _Which_ shell? Have you read e.g. https://stackoverflow.com/q/5934394/3001761? – jonrsharpe Jun 12 '23 at 11:23
  • No. However, you can write your customized shell script. Check this post - https://stackoverflow.com/questions/6467/date-arithmetic-in-unix-shell-scripts. – madD7 Jun 12 '23 at 11:23

1 Answers1

2

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.

Jiraiya
  • 52
  • 7