shell sleep until next full minute
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
To execute a script on the next full minute I want to tell the sleep
command to sleep until the next full minute. How can I do this?
shell sleep
add a comment |Â
up vote
3
down vote
favorite
To execute a script on the next full minute I want to tell the sleep
command to sleep until the next full minute. How can I do this?
shell sleep
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
To execute a script on the next full minute I want to tell the sleep
command to sleep until the next full minute. How can I do this?
shell sleep
To execute a script on the next full minute I want to tell the sleep
command to sleep until the next full minute. How can I do this?
shell sleep
shell sleep
asked Apr 6 '15 at 18:40
nnn
426139
426139
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
10
down vote
Ask for the date in seconds: date +%s
and calculate the reminder of the devision with 60 (modulo: %
). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).
sleep $((60 - $(date +%s) % 60)) &&
<yourscript>
To just sleep until the next full minute you can even make it shorter (without the modulo):
sleep $((60 - $(date +%S) )) &&
<yourscript>
Also be aware of this question and answer: sleep until next occurence of specific time.
5
This computation is overkill, sincedate
provides not only "seconds since epoch" but also plain "seconds". Sosleep $((60 - $(date +%S) ))
suffices.
â Janis
Apr 6 '15 at 19:22
good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
â nnn
Apr 7 '15 at 5:46
For a hypothetical other question than the one asked, yes. But be aware thatdate
's format specifier%s
(lower case) is also non-standard.
â Janis
Apr 7 '15 at 11:21
add a comment |Â
up vote
0
down vote
sleep $(( 60 - 10#$(date +%S) ))
sleeps until the next full minute. Don't forget the 10#
prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.
Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'sleep $(( 60 - $(date +%-S) ))
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
Ask for the date in seconds: date +%s
and calculate the reminder of the devision with 60 (modulo: %
). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).
sleep $((60 - $(date +%s) % 60)) &&
<yourscript>
To just sleep until the next full minute you can even make it shorter (without the modulo):
sleep $((60 - $(date +%S) )) &&
<yourscript>
Also be aware of this question and answer: sleep until next occurence of specific time.
5
This computation is overkill, sincedate
provides not only "seconds since epoch" but also plain "seconds". Sosleep $((60 - $(date +%S) ))
suffices.
â Janis
Apr 6 '15 at 19:22
good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
â nnn
Apr 7 '15 at 5:46
For a hypothetical other question than the one asked, yes. But be aware thatdate
's format specifier%s
(lower case) is also non-standard.
â Janis
Apr 7 '15 at 11:21
add a comment |Â
up vote
10
down vote
Ask for the date in seconds: date +%s
and calculate the reminder of the devision with 60 (modulo: %
). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).
sleep $((60 - $(date +%s) % 60)) &&
<yourscript>
To just sleep until the next full minute you can even make it shorter (without the modulo):
sleep $((60 - $(date +%S) )) &&
<yourscript>
Also be aware of this question and answer: sleep until next occurence of specific time.
5
This computation is overkill, sincedate
provides not only "seconds since epoch" but also plain "seconds". Sosleep $((60 - $(date +%S) ))
suffices.
â Janis
Apr 6 '15 at 19:22
good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
â nnn
Apr 7 '15 at 5:46
For a hypothetical other question than the one asked, yes. But be aware thatdate
's format specifier%s
(lower case) is also non-standard.
â Janis
Apr 7 '15 at 11:21
add a comment |Â
up vote
10
down vote
up vote
10
down vote
Ask for the date in seconds: date +%s
and calculate the reminder of the devision with 60 (modulo: %
). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).
sleep $((60 - $(date +%s) % 60)) &&
<yourscript>
To just sleep until the next full minute you can even make it shorter (without the modulo):
sleep $((60 - $(date +%S) )) &&
<yourscript>
Also be aware of this question and answer: sleep until next occurence of specific time.
Ask for the date in seconds: date +%s
and calculate the reminder of the devision with 60 (modulo: %
). If you calculate 60 minus the modulo you get the remaining seconds to the next full minute. You could change this to wait until the next full hour (change 60 to 3600).
sleep $((60 - $(date +%s) % 60)) &&
<yourscript>
To just sleep until the next full minute you can even make it shorter (without the modulo):
sleep $((60 - $(date +%S) )) &&
<yourscript>
Also be aware of this question and answer: sleep until next occurence of specific time.
edited Apr 13 '17 at 12:36
Communityâ¦
1
1
answered Apr 6 '15 at 18:40
nnn
426139
426139
5
This computation is overkill, sincedate
provides not only "seconds since epoch" but also plain "seconds". Sosleep $((60 - $(date +%S) ))
suffices.
â Janis
Apr 6 '15 at 19:22
good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
â nnn
Apr 7 '15 at 5:46
For a hypothetical other question than the one asked, yes. But be aware thatdate
's format specifier%s
(lower case) is also non-standard.
â Janis
Apr 7 '15 at 11:21
add a comment |Â
5
This computation is overkill, sincedate
provides not only "seconds since epoch" but also plain "seconds". Sosleep $((60 - $(date +%S) ))
suffices.
â Janis
Apr 6 '15 at 19:22
good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
â nnn
Apr 7 '15 at 5:46
For a hypothetical other question than the one asked, yes. But be aware thatdate
's format specifier%s
(lower case) is also non-standard.
â Janis
Apr 7 '15 at 11:21
5
5
This computation is overkill, since
date
provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) ))
suffices.â Janis
Apr 6 '15 at 19:22
This computation is overkill, since
date
provides not only "seconds since epoch" but also plain "seconds". So sleep $((60 - $(date +%S) ))
suffices.â Janis
Apr 6 '15 at 19:22
good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
â nnn
Apr 7 '15 at 5:46
good to know that it always can be done shorter, I will edit it. But for every other timespan you will need seconds since epoch, right?
â nnn
Apr 7 '15 at 5:46
For a hypothetical other question than the one asked, yes. But be aware that
date
's format specifier %s
(lower case) is also non-standard.â Janis
Apr 7 '15 at 11:21
For a hypothetical other question than the one asked, yes. But be aware that
date
's format specifier %s
(lower case) is also non-standard.â Janis
Apr 7 '15 at 11:21
add a comment |Â
up vote
0
down vote
sleep $(( 60 - 10#$(date +%S) ))
sleeps until the next full minute. Don't forget the 10#
prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.
Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'sleep $(( 60 - $(date +%-S) ))
add a comment |Â
up vote
0
down vote
sleep $(( 60 - 10#$(date +%S) ))
sleeps until the next full minute. Don't forget the 10#
prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.
Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'sleep $(( 60 - $(date +%-S) ))
add a comment |Â
up vote
0
down vote
up vote
0
down vote
sleep $(( 60 - 10#$(date +%S) ))
sleeps until the next full minute. Don't forget the 10#
prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.
Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'sleep $(( 60 - $(date +%-S) ))
sleep $(( 60 - 10#$(date +%S) ))
sleeps until the next full minute. Don't forget the 10#
prefix! Otherwise your code will interpret "08" and "09" as invalid references to an octal number.
Or you can prevent the date command from padding the seconds with '0' by following the '%' with '-'sleep $(( 60 - $(date +%-S) ))
edited 4 mins ago
Communityâ¦
1
1
answered Apr 23 at 21:00
William Dye
111
111
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f194655%2fshell-sleep-until-next-full-minute%23new-answer', 'question_page');
);
Post as a guest
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
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
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