Date & Time loop in bash Announcing the arrival of Valued Associate #679: Cesar Manara ...
How to call a function with default parameter through a pointer to function that is the return of another function?
Why aren't air breathing engines used as small first stages
Single word antonym of "flightless"
Identifying polygons that intersect with another layer using QGIS?
How do I stop a creek from eroding my steep embankment?
Why is "Consequences inflicted." not a sentence?
The logistics of corpse disposal
How can I make names more distinctive without making them longer?
What causes the vertical darker bands in my photo?
How to find out what spells would be useless to a blind NPC spellcaster?
What's the meaning of 間時肆拾貳 at a car parking sign
Resolving to minmaj7
How to align text above triangle figure
What does the "x" in "x86" represent?
How to tell that you are a giant?
How do pianists reach extremely loud dynamics?
String `!23` is replaced with `docker` in command line
How discoverable are IPv6 addresses and AAAA names by potential attackers?
Output the ŋarâþ crîþ alphabet song without using (m)any letters
2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?
How to answer "Have you ever been terminated?"
Why did the rest of the Eastern Bloc not invade Yugoslavia?
What is Wonderstone and are there any references to it pre-1982?
English words in a non-english sci-fi novel
Date & Time loop in bash
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionHow to get elapsed time from two “text based” datesshell script to do some text manipulation of text file data structure and slight content changesLogrotate not picking up or acting on new configuration fileAny caveats to using bash disown from a shell script as an alternative to screen?Trouble referring to the working directory in a shell script loopparallel processing reading from a file in a loopGetting a range of lines between timestamps from /var/log/messagesSimultaneously run curl and a process timerGet the latest timestamp from a set of files based on first line in a fileCreate a script to check the date, time and string and trigger a mail
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
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
First time loop it should go like below,
https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z
Second time loop it should go like below
https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z
Last time loop like below,
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
- Yesterday date always
- Format GMT
- 24 times loop
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.
#!/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
bash shell-script shell bashrc
add a comment |
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
First time loop it should go like below,
https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z
Second time loop it should go like below
https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z
Last time loop like below,
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
- Yesterday date always
- Format GMT
- 24 times loop
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.
#!/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
bash shell-script shell bashrc
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 '18 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 '18 at 12:44
that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 '18 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 '18 at 13:10
add a comment |
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
First time loop it should go like below,
https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z
Second time loop it should go like below
https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z
Last time loop like below,
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
- Yesterday date always
- Format GMT
- 24 times loop
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.
#!/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
bash shell-script shell bashrc
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
First time loop it should go like below,
https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z
Second time loop it should go like below
https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z
Last time loop like below,
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
- Yesterday date always
- Format GMT
- 24 times loop
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.
#!/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
bash shell-script shell bashrc
bash shell-script shell bashrc
edited 5 hours ago
Rui F Ribeiro
42.1k1484142
42.1k1484142
asked Apr 27 '18 at 12:05
JhonyJhony
145
145
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 '18 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 '18 at 12:44
that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 '18 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 '18 at 13:10
add a comment |
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 '18 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 '18 at 12:44
that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 12:44
that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 '18 at 13:09
that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 '18 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 '18 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 '18 at 13:10
add a comment |
2 Answers
2
active
oldest
votes
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
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 '18 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 '18 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 '18 at 13:18
@Jhony don't useecho
where I've usedprintf
. They're different commands for a reason.
– roaima
Apr 27 '18 at 13:18
i have created script file with the above code as test.sh and running in linux environment
– Jhony
Apr 27 '18 at 13:19
|
show 11 more comments
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
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
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 '18 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 '18 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 '18 at 13:18
@Jhony don't useecho
where I've usedprintf
. They're different commands for a reason.
– roaima
Apr 27 '18 at 13:18
i have created script file with the above code as test.sh and running in linux environment
– Jhony
Apr 27 '18 at 13:19
|
show 11 more comments
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
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 '18 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 '18 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 '18 at 13:18
@Jhony don't useecho
where I've usedprintf
. They're different commands for a reason.
– roaima
Apr 27 '18 at 13:18
i have created script file with the above code as test.sh and running in linux environment
– Jhony
Apr 27 '18 at 13:19
|
show 11 more comments
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
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
edited Apr 30 '18 at 9:44
answered Apr 27 '18 at 13:09
roaimaroaima
46.2k758124
46.2k758124
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 '18 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 '18 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 '18 at 13:18
@Jhony don't useecho
where I've usedprintf
. They're different commands for a reason.
– roaima
Apr 27 '18 at 13:18
i have created script file with the above code as test.sh and running in linux environment
– Jhony
Apr 27 '18 at 13:19
|
show 11 more comments
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 '18 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 '18 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 '18 at 13:18
@Jhony don't useecho
where I've usedprintf
. They're different commands for a reason.
– roaima
Apr 27 '18 at 13:18
i have created script file with the above code as test.sh and running in linux environment
– Jhony
Apr 27 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 13:18
@Jhony don't use
echo
where I've used printf
. They're different commands for a reason.– roaima
Apr 27 '18 at 13:18
@Jhony don't use
echo
where I've used printf
. They're different commands for a reason.– roaima
Apr 27 '18 at 13:18
i have created script file with the above code as test.sh and running in linux environment
– Jhony
Apr 27 '18 at 13:19
i have created script file with the above code as test.sh and running in linux environment
– Jhony
Apr 27 '18 at 13:19
|
show 11 more comments
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
add a comment |
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
add a comment |
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
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
answered Apr 30 '18 at 11:19
JhonyJhony
145
145
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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 '18 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 '18 at 12:44
that is correct. I took hour and appended the minutes and seconds.
– Jhony
Apr 27 '18 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 '18 at 13:10