Figuring out the remaining seconds left until a certain time with bash?
up vote
0
down vote
favorite
I'm thinking about extracting the time from the 'date' command, subtracting a certain time in the future from it to get the number of seconds left until 'date' reaches that time, then to divide that number by 60 for minutes, and 60 for hours.
I want to use this as an argument for the 'shutdown' command for example.
how do I do this?
bash shell-script scripting
New contributor
add a comment |
up vote
0
down vote
favorite
I'm thinking about extracting the time from the 'date' command, subtracting a certain time in the future from it to get the number of seconds left until 'date' reaches that time, then to divide that number by 60 for minutes, and 60 for hours.
I want to use this as an argument for the 'shutdown' command for example.
how do I do this?
bash shell-script scripting
New contributor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm thinking about extracting the time from the 'date' command, subtracting a certain time in the future from it to get the number of seconds left until 'date' reaches that time, then to divide that number by 60 for minutes, and 60 for hours.
I want to use this as an argument for the 'shutdown' command for example.
how do I do this?
bash shell-script scripting
New contributor
I'm thinking about extracting the time from the 'date' command, subtracting a certain time in the future from it to get the number of seconds left until 'date' reaches that time, then to divide that number by 60 for minutes, and 60 for hours.
I want to use this as an argument for the 'shutdown' command for example.
how do I do this?
bash shell-script scripting
bash shell-script scripting
New contributor
New contributor
edited 2 days ago
Rui F Ribeiro
38.5k1479128
38.5k1479128
New contributor
asked 2 days ago
dudawe
31
31
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Something like this?
echo $(( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ))
59856
Great! Thank you, foot man
– dudawe
2 days ago
You're welcome ;) Feel free to up-vote or accept :D the answer.
– tink
2 days ago
how do I divide by 60? in the same command?
– dudawe
2 days ago
` echo $(( ( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ) / 60 ))`
– tink
2 days ago
1
Awesome! I tried without the additional brackets (noob)
– dudawe
2 days ago
add a comment |
up vote
0
down vote
The conversion to a time string could be done directly in bash (less than 24 hours):
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' 123
00:02:03
The time difference could be found with simple math:
$ now=$(printf '%(%s)T')
$ future=$(date -d '+10 hours' '+%s')
$ tdiff=$(( future - now ))
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' "$tdiff"
10:00:00
To get up to 364 days use this:
now=$(printf '%(%s)T')
future=$(date -d '+10 hour' '+%s')
tdiff=$(( future - now ))
j=$(( $(TZ=UTC0 printf '%(%j)T' "$tdiff") - 1 ))
TZ=UTC0 printf '%s days %(%H:%M:%S)Tn' "$j" "$tdiff"
0 days 10:00:00
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Something like this?
echo $(( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ))
59856
Great! Thank you, foot man
– dudawe
2 days ago
You're welcome ;) Feel free to up-vote or accept :D the answer.
– tink
2 days ago
how do I divide by 60? in the same command?
– dudawe
2 days ago
` echo $(( ( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ) / 60 ))`
– tink
2 days ago
1
Awesome! I tried without the additional brackets (noob)
– dudawe
2 days ago
add a comment |
up vote
1
down vote
accepted
Something like this?
echo $(( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ))
59856
Great! Thank you, foot man
– dudawe
2 days ago
You're welcome ;) Feel free to up-vote or accept :D the answer.
– tink
2 days ago
how do I divide by 60? in the same command?
– dudawe
2 days ago
` echo $(( ( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ) / 60 ))`
– tink
2 days ago
1
Awesome! I tried without the additional brackets (noob)
– dudawe
2 days ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Something like this?
echo $(( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ))
59856
Something like this?
echo $(( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ))
59856
answered 2 days ago
tink
4,07511218
4,07511218
Great! Thank you, foot man
– dudawe
2 days ago
You're welcome ;) Feel free to up-vote or accept :D the answer.
– tink
2 days ago
how do I divide by 60? in the same command?
– dudawe
2 days ago
` echo $(( ( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ) / 60 ))`
– tink
2 days ago
1
Awesome! I tried without the additional brackets (noob)
– dudawe
2 days ago
add a comment |
Great! Thank you, foot man
– dudawe
2 days ago
You're welcome ;) Feel free to up-vote or accept :D the answer.
– tink
2 days ago
how do I divide by 60? in the same command?
– dudawe
2 days ago
` echo $(( ( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ) / 60 ))`
– tink
2 days ago
1
Awesome! I tried without the additional brackets (noob)
– dudawe
2 days ago
Great! Thank you, foot man
– dudawe
2 days ago
Great! Thank you, foot man
– dudawe
2 days ago
You're welcome ;) Feel free to up-vote or accept :D the answer.
– tink
2 days ago
You're welcome ;) Feel free to up-vote or accept :D the answer.
– tink
2 days ago
how do I divide by 60? in the same command?
– dudawe
2 days ago
how do I divide by 60? in the same command?
– dudawe
2 days ago
` echo $(( ( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ) / 60 ))`
– tink
2 days ago
` echo $(( ( $(date +%s -d "tomorrow 12:00") - $( date +%s ) ) / 60 ))`
– tink
2 days ago
1
1
Awesome! I tried without the additional brackets (noob)
– dudawe
2 days ago
Awesome! I tried without the additional brackets (noob)
– dudawe
2 days ago
add a comment |
up vote
0
down vote
The conversion to a time string could be done directly in bash (less than 24 hours):
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' 123
00:02:03
The time difference could be found with simple math:
$ now=$(printf '%(%s)T')
$ future=$(date -d '+10 hours' '+%s')
$ tdiff=$(( future - now ))
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' "$tdiff"
10:00:00
To get up to 364 days use this:
now=$(printf '%(%s)T')
future=$(date -d '+10 hour' '+%s')
tdiff=$(( future - now ))
j=$(( $(TZ=UTC0 printf '%(%j)T' "$tdiff") - 1 ))
TZ=UTC0 printf '%s days %(%H:%M:%S)Tn' "$j" "$tdiff"
0 days 10:00:00
add a comment |
up vote
0
down vote
The conversion to a time string could be done directly in bash (less than 24 hours):
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' 123
00:02:03
The time difference could be found with simple math:
$ now=$(printf '%(%s)T')
$ future=$(date -d '+10 hours' '+%s')
$ tdiff=$(( future - now ))
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' "$tdiff"
10:00:00
To get up to 364 days use this:
now=$(printf '%(%s)T')
future=$(date -d '+10 hour' '+%s')
tdiff=$(( future - now ))
j=$(( $(TZ=UTC0 printf '%(%j)T' "$tdiff") - 1 ))
TZ=UTC0 printf '%s days %(%H:%M:%S)Tn' "$j" "$tdiff"
0 days 10:00:00
add a comment |
up vote
0
down vote
up vote
0
down vote
The conversion to a time string could be done directly in bash (less than 24 hours):
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' 123
00:02:03
The time difference could be found with simple math:
$ now=$(printf '%(%s)T')
$ future=$(date -d '+10 hours' '+%s')
$ tdiff=$(( future - now ))
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' "$tdiff"
10:00:00
To get up to 364 days use this:
now=$(printf '%(%s)T')
future=$(date -d '+10 hour' '+%s')
tdiff=$(( future - now ))
j=$(( $(TZ=UTC0 printf '%(%j)T' "$tdiff") - 1 ))
TZ=UTC0 printf '%s days %(%H:%M:%S)Tn' "$j" "$tdiff"
0 days 10:00:00
The conversion to a time string could be done directly in bash (less than 24 hours):
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' 123
00:02:03
The time difference could be found with simple math:
$ now=$(printf '%(%s)T')
$ future=$(date -d '+10 hours' '+%s')
$ tdiff=$(( future - now ))
$ TZ=UTC0 printf '%(%H:%M:%S)Tn' "$tdiff"
10:00:00
To get up to 364 days use this:
now=$(printf '%(%s)T')
future=$(date -d '+10 hour' '+%s')
tdiff=$(( future - now ))
j=$(( $(TZ=UTC0 printf '%(%j)T' "$tdiff") - 1 ))
TZ=UTC0 printf '%s days %(%H:%M:%S)Tn' "$j" "$tdiff"
0 days 10:00:00
edited 2 days ago
answered 2 days ago
Isaac
10.8k11447
10.8k11447
add a comment |
add a comment |
dudawe is a new contributor. Be nice, and check out our Code of Conduct.
dudawe is a new contributor. Be nice, and check out our Code of Conduct.
dudawe is a new contributor. Be nice, and check out our Code of Conduct.
dudawe is a new contributor. Be nice, and check out our Code of Conduct.
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f486510%2ffiguring-out-the-remaining-seconds-left-until-a-certain-time-with-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