Date & Time loop in bash

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am trying to download the yesterday logs through an external API, For API I need to provide a date range from & to as input parameters.



From API I can download 1 hour log max for each call.



So if I want to download yesterday complete log. I need to call the API for 24 times with yesterday date(every hour time).



Note API will support only GMT time only. So need to provide GMT time.




Eg :- https://abcd.com/logs?start=FROM_DATE&end=TO_DATE





  1. First time loop it should go like below,


  2. https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z


  3. Second time loop it should go like below


  4. https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z


  5. Last time loop like below,


  6. https://abcd.com/logs?start=29-04-2018T23:00:00Z&end=29-04-2018T23:59:59Z

This script i will add in cron schedule, so everyday once it will get triggered and download yesterday 24 hour log complete.



Key points are



  1. Yesterday date always

  2. Format GMT

  3. 24 times loop

Hope it is clear. The below mentioned answers are throwing error. I started with this script, it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time. Someone please help me.



#!/bin/bash
FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"%H":00:00""Z")
for i in 0..3
do
echo "FROM_DATE : $FROM_DATE"
TO_DATE=$(date -u +%Y-%m-%d"T"%H":59:59""Z" -d "1 day ago""$date + $i hour")
echo "TO_DATE : $TO_DATE"
FROM_DATE=$(date -u +%Y-%m-%d"T"%H":00:00""Z" -d "1 day ago""$date + $i hour""$date + 1 hour")
done






share|improve this question





















  • it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time
    – Jhony
    Apr 27 at 12:12










  • Hard to read a script in a comment. I added it to the question, but please verify it. Something seems to have been eaten in the comment, so edit it to correct it.
    – Philippos
    Apr 27 at 12:44










  • that is correct. I took hour and appended the minutes and seconds.
    – Jhony
    Apr 27 at 13:09










  • Problem is my loop needs to start with GMT 00:00:00 instead of considering current hour. Please help it
    – Jhony
    Apr 27 at 13:10















up vote
1
down vote

favorite












I am trying to download the yesterday logs through an external API, For API I need to provide a date range from & to as input parameters.



From API I can download 1 hour log max for each call.



So if I want to download yesterday complete log. I need to call the API for 24 times with yesterday date(every hour time).



Note API will support only GMT time only. So need to provide GMT time.




Eg :- https://abcd.com/logs?start=FROM_DATE&end=TO_DATE





  1. First time loop it should go like below,


  2. https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z


  3. Second time loop it should go like below


  4. https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z


  5. Last time loop like below,


  6. https://abcd.com/logs?start=29-04-2018T23:00:00Z&end=29-04-2018T23:59:59Z

This script i will add in cron schedule, so everyday once it will get triggered and download yesterday 24 hour log complete.



Key points are



  1. Yesterday date always

  2. Format GMT

  3. 24 times loop

Hope it is clear. The below mentioned answers are throwing error. I started with this script, it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time. Someone please help me.



#!/bin/bash
FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"%H":00:00""Z")
for i in 0..3
do
echo "FROM_DATE : $FROM_DATE"
TO_DATE=$(date -u +%Y-%m-%d"T"%H":59:59""Z" -d "1 day ago""$date + $i hour")
echo "TO_DATE : $TO_DATE"
FROM_DATE=$(date -u +%Y-%m-%d"T"%H":00:00""Z" -d "1 day ago""$date + $i hour""$date + 1 hour")
done






share|improve this question





















  • it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time
    – Jhony
    Apr 27 at 12:12










  • Hard to read a script in a comment. I added it to the question, but please verify it. Something seems to have been eaten in the comment, so edit it to correct it.
    – Philippos
    Apr 27 at 12:44










  • that is correct. I took hour and appended the minutes and seconds.
    – Jhony
    Apr 27 at 13:09










  • Problem is my loop needs to start with GMT 00:00:00 instead of considering current hour. Please help it
    – Jhony
    Apr 27 at 13:10













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to download the yesterday logs through an external API, For API I need to provide a date range from & to as input parameters.



From API I can download 1 hour log max for each call.



So if I want to download yesterday complete log. I need to call the API for 24 times with yesterday date(every hour time).



Note API will support only GMT time only. So need to provide GMT time.




Eg :- https://abcd.com/logs?start=FROM_DATE&end=TO_DATE





  1. First time loop it should go like below,


  2. https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z


  3. Second time loop it should go like below


  4. https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z


  5. Last time loop like below,


  6. https://abcd.com/logs?start=29-04-2018T23:00:00Z&end=29-04-2018T23:59:59Z

This script i will add in cron schedule, so everyday once it will get triggered and download yesterday 24 hour log complete.



Key points are



  1. Yesterday date always

  2. Format GMT

  3. 24 times loop

Hope it is clear. The below mentioned answers are throwing error. I started with this script, it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time. Someone please help me.



#!/bin/bash
FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"%H":00:00""Z")
for i in 0..3
do
echo "FROM_DATE : $FROM_DATE"
TO_DATE=$(date -u +%Y-%m-%d"T"%H":59:59""Z" -d "1 day ago""$date + $i hour")
echo "TO_DATE : $TO_DATE"
FROM_DATE=$(date -u +%Y-%m-%d"T"%H":00:00""Z" -d "1 day ago""$date + $i hour""$date + 1 hour")
done






share|improve this question













I am trying to download the yesterday logs through an external API, For API I need to provide a date range from & to as input parameters.



From API I can download 1 hour log max for each call.



So if I want to download yesterday complete log. I need to call the API for 24 times with yesterday date(every hour time).



Note API will support only GMT time only. So need to provide GMT time.




Eg :- https://abcd.com/logs?start=FROM_DATE&end=TO_DATE





  1. First time loop it should go like below,


  2. https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z


  3. Second time loop it should go like below


  4. https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z


  5. Last time loop like below,


  6. https://abcd.com/logs?start=29-04-2018T23:00:00Z&end=29-04-2018T23:59:59Z

This script i will add in cron schedule, so everyday once it will get triggered and download yesterday 24 hour log complete.



Key points are



  1. Yesterday date always

  2. Format GMT

  3. 24 times loop

Hope it is clear. The below mentioned answers are throwing error. I started with this script, it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time. Someone please help me.



#!/bin/bash
FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"%H":00:00""Z")
for i in 0..3
do
echo "FROM_DATE : $FROM_DATE"
TO_DATE=$(date -u +%Y-%m-%d"T"%H":59:59""Z" -d "1 day ago""$date + $i hour")
echo "TO_DATE : $TO_DATE"
FROM_DATE=$(date -u +%Y-%m-%d"T"%H":00:00""Z" -d "1 day ago""$date + $i hour""$date + 1 hour")
done








share|improve this question












share|improve this question




share|improve this question








edited Apr 30 at 7:09
























asked Apr 27 at 12:05









Jhony

144




144











  • it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time
    – Jhony
    Apr 27 at 12:12










  • Hard to read a script in a comment. I added it to the question, but please verify it. Something seems to have been eaten in the comment, so edit it to correct it.
    – Philippos
    Apr 27 at 12:44










  • that is correct. I took hour and appended the minutes and seconds.
    – Jhony
    Apr 27 at 13:09










  • Problem is my loop needs to start with GMT 00:00:00 instead of considering current hour. Please help it
    – Jhony
    Apr 27 at 13:10

















  • it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time
    – Jhony
    Apr 27 at 12:12










  • Hard to read a script in a comment. I added it to the question, but please verify it. Something seems to have been eaten in the comment, so edit it to correct it.
    – Philippos
    Apr 27 at 12:44










  • that is correct. I took hour and appended the minutes and seconds.
    – Jhony
    Apr 27 at 13:09










  • Problem is my loop needs to start with GMT 00:00:00 instead of considering current hour. Please help it
    – Jhony
    Apr 27 at 13:10
















it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time
– Jhony
Apr 27 at 12:12




it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time
– Jhony
Apr 27 at 12:12












Hard to read a script in a comment. I added it to the question, but please verify it. Something seems to have been eaten in the comment, so edit it to correct it.
– Philippos
Apr 27 at 12:44




Hard to read a script in a comment. I added it to the question, but please verify it. Something seems to have been eaten in the comment, so edit it to correct it.
– Philippos
Apr 27 at 12:44












that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 at 13:09




that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 at 13:09












Problem is my loop needs to start with GMT 00:00:00 instead of considering current hour. Please help it
– Jhony
Apr 27 at 13:10





Problem is my loop needs to start with GMT 00:00:00 instead of considering current hour. Please help it
– Jhony
Apr 27 at 13:10











2 Answers
2






active

oldest

votes

















up vote
1
down vote













Try this.



#!/bin/bash
#
yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
for hour in 0..23
do
printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:59Zn" $yesterday $hour $yesterday $hour
done


It won't handle the occasional leap seconds. If you need that, use this more complex code where the last range of the day may need to go from 23:00:00 to 23:59:60, but ensure that your target application can also handle this:



#!/bin/bash
#
yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
leapsecond=$(date --utc --date @$(( $(date --utc --date '00:00:00' +%s) -1 )) +'%S')
lastsecond=59

for hour in 0..23
do
[[ hour == 23 ]] && lastsecond=$leapsecond
printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:%02dZn" $yesterday $hour $yesterday $hour $lastsecond
done





share|improve this answer























  • the out put of the first code is like below : invalid number printf: 0 : invalid number printf: 0 T00:59:59Z), TO_DATE(2018-04-26
    – Jhony
    Apr 27 at 13:17











  • Like what below? Please EDIT YOUR QUESTION to show us what you actually want, rather than expecting us to read your mind or try and interpret poorly formatted comments.
    – roaima
    Apr 27 at 13:18











  • i have just modified printf to echo it is coming like this 0018-04-26sT%02d:00:00Z), TO_DATE(%sT%02d:59:59Z)n 2018-04-26
    – Jhony
    Apr 27 at 13:18










  • @Jhony don't use echo where I've used printf. They're different commands for a reason.
    – roaima
    Apr 27 at 13:18










  • i have created script file with the above code as test.sh and running in linux environment
    – Jhony
    Apr 27 at 13:19

















up vote
0
down vote













I am getting as expected output.



#!/bin/bash
for i in 00..23
do FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"$i":00:00Z")
echo "FROM_DATE:" $FROM_DATE | tr -d 'r'
TO_DATE=$(date -u +%Y-%m-%d"T"$i":59:59Z" -d "1 day ago")
echo "TO_DATE : $TO_DATE" | tr -d 'r'
done


Thanks a lot for your help






share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440409%2fdate-time-loop-in-bash%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Try this.



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    for hour in 0..23
    do
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:59Zn" $yesterday $hour $yesterday $hour
    done


    It won't handle the occasional leap seconds. If you need that, use this more complex code where the last range of the day may need to go from 23:00:00 to 23:59:60, but ensure that your target application can also handle this:



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    leapsecond=$(date --utc --date @$(( $(date --utc --date '00:00:00' +%s) -1 )) +'%S')
    lastsecond=59

    for hour in 0..23
    do
    [[ hour == 23 ]] && lastsecond=$leapsecond
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:%02dZn" $yesterday $hour $yesterday $hour $lastsecond
    done





    share|improve this answer























    • the out put of the first code is like below : invalid number printf: 0 : invalid number printf: 0 T00:59:59Z), TO_DATE(2018-04-26
      – Jhony
      Apr 27 at 13:17











    • Like what below? Please EDIT YOUR QUESTION to show us what you actually want, rather than expecting us to read your mind or try and interpret poorly formatted comments.
      – roaima
      Apr 27 at 13:18











    • i have just modified printf to echo it is coming like this 0018-04-26sT%02d:00:00Z), TO_DATE(%sT%02d:59:59Z)n 2018-04-26
      – Jhony
      Apr 27 at 13:18










    • @Jhony don't use echo where I've used printf. They're different commands for a reason.
      – roaima
      Apr 27 at 13:18










    • i have created script file with the above code as test.sh and running in linux environment
      – Jhony
      Apr 27 at 13:19














    up vote
    1
    down vote













    Try this.



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    for hour in 0..23
    do
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:59Zn" $yesterday $hour $yesterday $hour
    done


    It won't handle the occasional leap seconds. If you need that, use this more complex code where the last range of the day may need to go from 23:00:00 to 23:59:60, but ensure that your target application can also handle this:



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    leapsecond=$(date --utc --date @$(( $(date --utc --date '00:00:00' +%s) -1 )) +'%S')
    lastsecond=59

    for hour in 0..23
    do
    [[ hour == 23 ]] && lastsecond=$leapsecond
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:%02dZn" $yesterday $hour $yesterday $hour $lastsecond
    done





    share|improve this answer























    • the out put of the first code is like below : invalid number printf: 0 : invalid number printf: 0 T00:59:59Z), TO_DATE(2018-04-26
      – Jhony
      Apr 27 at 13:17











    • Like what below? Please EDIT YOUR QUESTION to show us what you actually want, rather than expecting us to read your mind or try and interpret poorly formatted comments.
      – roaima
      Apr 27 at 13:18











    • i have just modified printf to echo it is coming like this 0018-04-26sT%02d:00:00Z), TO_DATE(%sT%02d:59:59Z)n 2018-04-26
      – Jhony
      Apr 27 at 13:18










    • @Jhony don't use echo where I've used printf. They're different commands for a reason.
      – roaima
      Apr 27 at 13:18










    • i have created script file with the above code as test.sh and running in linux environment
      – Jhony
      Apr 27 at 13:19












    up vote
    1
    down vote










    up vote
    1
    down vote









    Try this.



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    for hour in 0..23
    do
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:59Zn" $yesterday $hour $yesterday $hour
    done


    It won't handle the occasional leap seconds. If you need that, use this more complex code where the last range of the day may need to go from 23:00:00 to 23:59:60, but ensure that your target application can also handle this:



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    leapsecond=$(date --utc --date @$(( $(date --utc --date '00:00:00' +%s) -1 )) +'%S')
    lastsecond=59

    for hour in 0..23
    do
    [[ hour == 23 ]] && lastsecond=$leapsecond
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:%02dZn" $yesterday $hour $yesterday $hour $lastsecond
    done





    share|improve this answer















    Try this.



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    for hour in 0..23
    do
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:59Zn" $yesterday $hour $yesterday $hour
    done


    It won't handle the occasional leap seconds. If you need that, use this more complex code where the last range of the day may need to go from 23:00:00 to 23:59:60, but ensure that your target application can also handle this:



    #!/bin/bash
    #
    yesterday=$(date --utc --date 'yesterday' +'%Y-%m-%d')
    leapsecond=$(date --utc --date @$(( $(date --utc --date '00:00:00' +%s) -1 )) +'%S')
    lastsecond=59

    for hour in 0..23
    do
    [[ hour == 23 ]] && lastsecond=$leapsecond
    printf "https://abcd.com/logs?start=%sT%02d:00:00Z&end=%sT%02d:59:%02dZn" $yesterday $hour $yesterday $hour $lastsecond
    done






    share|improve this answer















    share|improve this answer



    share|improve this answer








    edited Apr 30 at 9:44


























    answered Apr 27 at 13:09









    roaima

    39.4k545106




    39.4k545106











    • the out put of the first code is like below : invalid number printf: 0 : invalid number printf: 0 T00:59:59Z), TO_DATE(2018-04-26
      – Jhony
      Apr 27 at 13:17











    • Like what below? Please EDIT YOUR QUESTION to show us what you actually want, rather than expecting us to read your mind or try and interpret poorly formatted comments.
      – roaima
      Apr 27 at 13:18











    • i have just modified printf to echo it is coming like this 0018-04-26sT%02d:00:00Z), TO_DATE(%sT%02d:59:59Z)n 2018-04-26
      – Jhony
      Apr 27 at 13:18










    • @Jhony don't use echo where I've used printf. They're different commands for a reason.
      – roaima
      Apr 27 at 13:18










    • i have created script file with the above code as test.sh and running in linux environment
      – Jhony
      Apr 27 at 13:19
















    • the out put of the first code is like below : invalid number printf: 0 : invalid number printf: 0 T00:59:59Z), TO_DATE(2018-04-26
      – Jhony
      Apr 27 at 13:17











    • Like what below? Please EDIT YOUR QUESTION to show us what you actually want, rather than expecting us to read your mind or try and interpret poorly formatted comments.
      – roaima
      Apr 27 at 13:18











    • i have just modified printf to echo it is coming like this 0018-04-26sT%02d:00:00Z), TO_DATE(%sT%02d:59:59Z)n 2018-04-26
      – Jhony
      Apr 27 at 13:18










    • @Jhony don't use echo where I've used printf. They're different commands for a reason.
      – roaima
      Apr 27 at 13:18










    • i have created script file with the above code as test.sh and running in linux environment
      – Jhony
      Apr 27 at 13:19















    the out put of the first code is like below : invalid number printf: 0 : invalid number printf: 0 T00:59:59Z), TO_DATE(2018-04-26
    – Jhony
    Apr 27 at 13:17





    the out put of the first code is like below : invalid number printf: 0 : invalid number printf: 0 T00:59:59Z), TO_DATE(2018-04-26
    – Jhony
    Apr 27 at 13:17













    Like what below? Please EDIT YOUR QUESTION to show us what you actually want, rather than expecting us to read your mind or try and interpret poorly formatted comments.
    – roaima
    Apr 27 at 13:18





    Like what below? Please EDIT YOUR QUESTION to show us what you actually want, rather than expecting us to read your mind or try and interpret poorly formatted comments.
    – roaima
    Apr 27 at 13:18













    i have just modified printf to echo it is coming like this 0018-04-26sT%02d:00:00Z), TO_DATE(%sT%02d:59:59Z)n 2018-04-26
    – Jhony
    Apr 27 at 13:18




    i have just modified printf to echo it is coming like this 0018-04-26sT%02d:00:00Z), TO_DATE(%sT%02d:59:59Z)n 2018-04-26
    – Jhony
    Apr 27 at 13:18












    @Jhony don't use echo where I've used printf. They're different commands for a reason.
    – roaima
    Apr 27 at 13:18




    @Jhony don't use echo where I've used printf. They're different commands for a reason.
    – roaima
    Apr 27 at 13:18












    i have created script file with the above code as test.sh and running in linux environment
    – Jhony
    Apr 27 at 13:19




    i have created script file with the above code as test.sh and running in linux environment
    – Jhony
    Apr 27 at 13:19












    up vote
    0
    down vote













    I am getting as expected output.



    #!/bin/bash
    for i in 00..23
    do FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"$i":00:00Z")
    echo "FROM_DATE:" $FROM_DATE | tr -d 'r'
    TO_DATE=$(date -u +%Y-%m-%d"T"$i":59:59Z" -d "1 day ago")
    echo "TO_DATE : $TO_DATE" | tr -d 'r'
    done


    Thanks a lot for your help






    share|improve this answer

























      up vote
      0
      down vote













      I am getting as expected output.



      #!/bin/bash
      for i in 00..23
      do FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"$i":00:00Z")
      echo "FROM_DATE:" $FROM_DATE | tr -d 'r'
      TO_DATE=$(date -u +%Y-%m-%d"T"$i":59:59Z" -d "1 day ago")
      echo "TO_DATE : $TO_DATE" | tr -d 'r'
      done


      Thanks a lot for your help






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I am getting as expected output.



        #!/bin/bash
        for i in 00..23
        do FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"$i":00:00Z")
        echo "FROM_DATE:" $FROM_DATE | tr -d 'r'
        TO_DATE=$(date -u +%Y-%m-%d"T"$i":59:59Z" -d "1 day ago")
        echo "TO_DATE : $TO_DATE" | tr -d 'r'
        done


        Thanks a lot for your help






        share|improve this answer













        I am getting as expected output.



        #!/bin/bash
        for i in 00..23
        do FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"$i":00:00Z")
        echo "FROM_DATE:" $FROM_DATE | tr -d 'r'
        TO_DATE=$(date -u +%Y-%m-%d"T"$i":59:59Z" -d "1 day ago")
        echo "TO_DATE : $TO_DATE" | tr -d 'r'
        done


        Thanks a lot for your help







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 30 at 11:19









        Jhony

        144




        144






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440409%2fdate-time-loop-in-bash%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay