How to convert seconds to hh:mm:ss format from output of another shell script
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
everyone
here is my script
/bin/wstalist | grep 'uptime'
Which is return value like "uptime": 3456,
yes there's a ,
coming with output.
These number are seconds. I want to convert it to hh:mm:ss format. and want it to be simple cause it will running by a router(busybox) in every minute.
So the problem is I don't know how.
Can someone help me? please.
shell-script shell busybox openwrt
add a comment |Â
up vote
0
down vote
favorite
everyone
here is my script
/bin/wstalist | grep 'uptime'
Which is return value like "uptime": 3456,
yes there's a ,
coming with output.
These number are seconds. I want to convert it to hh:mm:ss format. and want it to be simple cause it will running by a router(busybox) in every minute.
So the problem is I don't know how.
Can someone help me? please.
shell-script shell busybox openwrt
Can you elaborate a bit on what you're trying to accomplish? Are you asking how to take a number of seconds and covert that to hours/minutes/seconds (e.g., 3456 = 00:57:36)?
â Andy Dalton
Nov 15 '16 at 14:21
yes, it is. exactly as you said.
â Vermillion
Nov 15 '16 at 14:25
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
everyone
here is my script
/bin/wstalist | grep 'uptime'
Which is return value like "uptime": 3456,
yes there's a ,
coming with output.
These number are seconds. I want to convert it to hh:mm:ss format. and want it to be simple cause it will running by a router(busybox) in every minute.
So the problem is I don't know how.
Can someone help me? please.
shell-script shell busybox openwrt
everyone
here is my script
/bin/wstalist | grep 'uptime'
Which is return value like "uptime": 3456,
yes there's a ,
coming with output.
These number are seconds. I want to convert it to hh:mm:ss format. and want it to be simple cause it will running by a router(busybox) in every minute.
So the problem is I don't know how.
Can someone help me? please.
shell-script shell busybox openwrt
shell-script shell busybox openwrt
asked Nov 15 '16 at 14:08
Vermillion
32
32
Can you elaborate a bit on what you're trying to accomplish? Are you asking how to take a number of seconds and covert that to hours/minutes/seconds (e.g., 3456 = 00:57:36)?
â Andy Dalton
Nov 15 '16 at 14:21
yes, it is. exactly as you said.
â Vermillion
Nov 15 '16 at 14:25
add a comment |Â
Can you elaborate a bit on what you're trying to accomplish? Are you asking how to take a number of seconds and covert that to hours/minutes/seconds (e.g., 3456 = 00:57:36)?
â Andy Dalton
Nov 15 '16 at 14:21
yes, it is. exactly as you said.
â Vermillion
Nov 15 '16 at 14:25
Can you elaborate a bit on what you're trying to accomplish? Are you asking how to take a number of seconds and covert that to hours/minutes/seconds (e.g., 3456 = 00:57:36)?
â Andy Dalton
Nov 15 '16 at 14:21
Can you elaborate a bit on what you're trying to accomplish? Are you asking how to take a number of seconds and covert that to hours/minutes/seconds (e.g., 3456 = 00:57:36)?
â Andy Dalton
Nov 15 '16 at 14:21
yes, it is. exactly as you said.
â Vermillion
Nov 15 '16 at 14:25
yes, it is. exactly as you said.
â Vermillion
Nov 15 '16 at 14:25
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
line=$(/bin/wstalist | grep 'uptime')
sec=$line##*
sec=$sec%%,
h=$(( $sec / 3600 ))
m=$(( $(($sec - $h * 3600)) / 60 ))
s=$(($sec - $h * 3600 - $m * 60))
if [ $h -le 9 ];then h=0$h;fi
if [ $m -le 9 ];then m=0$m;fi
if [ $s -le 9 ];then s=0$s;fi
echo $h:$m:$s
That's what exactly I'm looking for! thank you very much!
â Vermillion
Nov 15 '16 at 14:41
after I ran it for a while. I think I found bugs. 1. hh:mm:ss format sometime show as xx:xxx:xx or xx:xx:xxx 2. it appear to be a wrong value so many times eg 00:00:32 event if /bin/wstalist returns so much value more than that. can you please look into it?
â Vermillion
Nov 16 '16 at 5:39
add a comment |Â
up vote
1
down vote
#!/bin/bash
# Here's the output from your command
output='"uptime": 3456,'
# Trim off the interesting bit
seconds="$(echo "$output" | awk ' print $2 ' | sed -e 's/,.*//')"
readonly SECONDS_PER_HOUR=3600
readonly SECONDS_PER_MINUTE=60
hours=$(($seconds / $SECONDS_PER_HOUR))
seconds=$(($seconds % $SECONDS_PER_HOUR))
minutes=$(($seconds / $SECONDS_PER_MINUTE))
seconds=$(($seconds % $SECONDS_PER_MINUTE))
printf "%02d:%02d:%02dn" $hours $minutes $seconds
thanks man. but it doesn't work for me. but I do appreciate your help!
â Vermillion
Nov 15 '16 at 14:40
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
line=$(/bin/wstalist | grep 'uptime')
sec=$line##*
sec=$sec%%,
h=$(( $sec / 3600 ))
m=$(( $(($sec - $h * 3600)) / 60 ))
s=$(($sec - $h * 3600 - $m * 60))
if [ $h -le 9 ];then h=0$h;fi
if [ $m -le 9 ];then m=0$m;fi
if [ $s -le 9 ];then s=0$s;fi
echo $h:$m:$s
That's what exactly I'm looking for! thank you very much!
â Vermillion
Nov 15 '16 at 14:41
after I ran it for a while. I think I found bugs. 1. hh:mm:ss format sometime show as xx:xxx:xx or xx:xx:xxx 2. it appear to be a wrong value so many times eg 00:00:32 event if /bin/wstalist returns so much value more than that. can you please look into it?
â Vermillion
Nov 16 '16 at 5:39
add a comment |Â
up vote
1
down vote
accepted
line=$(/bin/wstalist | grep 'uptime')
sec=$line##*
sec=$sec%%,
h=$(( $sec / 3600 ))
m=$(( $(($sec - $h * 3600)) / 60 ))
s=$(($sec - $h * 3600 - $m * 60))
if [ $h -le 9 ];then h=0$h;fi
if [ $m -le 9 ];then m=0$m;fi
if [ $s -le 9 ];then s=0$s;fi
echo $h:$m:$s
That's what exactly I'm looking for! thank you very much!
â Vermillion
Nov 15 '16 at 14:41
after I ran it for a while. I think I found bugs. 1. hh:mm:ss format sometime show as xx:xxx:xx or xx:xx:xxx 2. it appear to be a wrong value so many times eg 00:00:32 event if /bin/wstalist returns so much value more than that. can you please look into it?
â Vermillion
Nov 16 '16 at 5:39
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
line=$(/bin/wstalist | grep 'uptime')
sec=$line##*
sec=$sec%%,
h=$(( $sec / 3600 ))
m=$(( $(($sec - $h * 3600)) / 60 ))
s=$(($sec - $h * 3600 - $m * 60))
if [ $h -le 9 ];then h=0$h;fi
if [ $m -le 9 ];then m=0$m;fi
if [ $s -le 9 ];then s=0$s;fi
echo $h:$m:$s
line=$(/bin/wstalist | grep 'uptime')
sec=$line##*
sec=$sec%%,
h=$(( $sec / 3600 ))
m=$(( $(($sec - $h * 3600)) / 60 ))
s=$(($sec - $h * 3600 - $m * 60))
if [ $h -le 9 ];then h=0$h;fi
if [ $m -le 9 ];then m=0$m;fi
if [ $s -le 9 ];then s=0$s;fi
echo $h:$m:$s
edited 14 mins ago
Jeff Schaller
33.9k851113
33.9k851113
answered Nov 15 '16 at 14:28
Ipor Sircer
9,5011920
9,5011920
That's what exactly I'm looking for! thank you very much!
â Vermillion
Nov 15 '16 at 14:41
after I ran it for a while. I think I found bugs. 1. hh:mm:ss format sometime show as xx:xxx:xx or xx:xx:xxx 2. it appear to be a wrong value so many times eg 00:00:32 event if /bin/wstalist returns so much value more than that. can you please look into it?
â Vermillion
Nov 16 '16 at 5:39
add a comment |Â
That's what exactly I'm looking for! thank you very much!
â Vermillion
Nov 15 '16 at 14:41
after I ran it for a while. I think I found bugs. 1. hh:mm:ss format sometime show as xx:xxx:xx or xx:xx:xxx 2. it appear to be a wrong value so many times eg 00:00:32 event if /bin/wstalist returns so much value more than that. can you please look into it?
â Vermillion
Nov 16 '16 at 5:39
That's what exactly I'm looking for! thank you very much!
â Vermillion
Nov 15 '16 at 14:41
That's what exactly I'm looking for! thank you very much!
â Vermillion
Nov 15 '16 at 14:41
after I ran it for a while. I think I found bugs. 1. hh:mm:ss format sometime show as xx:xxx:xx or xx:xx:xxx 2. it appear to be a wrong value so many times eg 00:00:32 event if /bin/wstalist returns so much value more than that. can you please look into it?
â Vermillion
Nov 16 '16 at 5:39
after I ran it for a while. I think I found bugs. 1. hh:mm:ss format sometime show as xx:xxx:xx or xx:xx:xxx 2. it appear to be a wrong value so many times eg 00:00:32 event if /bin/wstalist returns so much value more than that. can you please look into it?
â Vermillion
Nov 16 '16 at 5:39
add a comment |Â
up vote
1
down vote
#!/bin/bash
# Here's the output from your command
output='"uptime": 3456,'
# Trim off the interesting bit
seconds="$(echo "$output" | awk ' print $2 ' | sed -e 's/,.*//')"
readonly SECONDS_PER_HOUR=3600
readonly SECONDS_PER_MINUTE=60
hours=$(($seconds / $SECONDS_PER_HOUR))
seconds=$(($seconds % $SECONDS_PER_HOUR))
minutes=$(($seconds / $SECONDS_PER_MINUTE))
seconds=$(($seconds % $SECONDS_PER_MINUTE))
printf "%02d:%02d:%02dn" $hours $minutes $seconds
thanks man. but it doesn't work for me. but I do appreciate your help!
â Vermillion
Nov 15 '16 at 14:40
add a comment |Â
up vote
1
down vote
#!/bin/bash
# Here's the output from your command
output='"uptime": 3456,'
# Trim off the interesting bit
seconds="$(echo "$output" | awk ' print $2 ' | sed -e 's/,.*//')"
readonly SECONDS_PER_HOUR=3600
readonly SECONDS_PER_MINUTE=60
hours=$(($seconds / $SECONDS_PER_HOUR))
seconds=$(($seconds % $SECONDS_PER_HOUR))
minutes=$(($seconds / $SECONDS_PER_MINUTE))
seconds=$(($seconds % $SECONDS_PER_MINUTE))
printf "%02d:%02d:%02dn" $hours $minutes $seconds
thanks man. but it doesn't work for me. but I do appreciate your help!
â Vermillion
Nov 15 '16 at 14:40
add a comment |Â
up vote
1
down vote
up vote
1
down vote
#!/bin/bash
# Here's the output from your command
output='"uptime": 3456,'
# Trim off the interesting bit
seconds="$(echo "$output" | awk ' print $2 ' | sed -e 's/,.*//')"
readonly SECONDS_PER_HOUR=3600
readonly SECONDS_PER_MINUTE=60
hours=$(($seconds / $SECONDS_PER_HOUR))
seconds=$(($seconds % $SECONDS_PER_HOUR))
minutes=$(($seconds / $SECONDS_PER_MINUTE))
seconds=$(($seconds % $SECONDS_PER_MINUTE))
printf "%02d:%02d:%02dn" $hours $minutes $seconds
#!/bin/bash
# Here's the output from your command
output='"uptime": 3456,'
# Trim off the interesting bit
seconds="$(echo "$output" | awk ' print $2 ' | sed -e 's/,.*//')"
readonly SECONDS_PER_HOUR=3600
readonly SECONDS_PER_MINUTE=60
hours=$(($seconds / $SECONDS_PER_HOUR))
seconds=$(($seconds % $SECONDS_PER_HOUR))
minutes=$(($seconds / $SECONDS_PER_MINUTE))
seconds=$(($seconds % $SECONDS_PER_MINUTE))
printf "%02d:%02d:%02dn" $hours $minutes $seconds
answered Nov 15 '16 at 14:31
Andy Dalton
4,9891520
4,9891520
thanks man. but it doesn't work for me. but I do appreciate your help!
â Vermillion
Nov 15 '16 at 14:40
add a comment |Â
thanks man. but it doesn't work for me. but I do appreciate your help!
â Vermillion
Nov 15 '16 at 14:40
thanks man. but it doesn't work for me. but I do appreciate your help!
â Vermillion
Nov 15 '16 at 14:40
thanks man. but it doesn't work for me. but I do appreciate your help!
â Vermillion
Nov 15 '16 at 14:40
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%2f323429%2fhow-to-convert-seconds-to-hhmmss-format-from-output-of-another-shell-script%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
Can you elaborate a bit on what you're trying to accomplish? Are you asking how to take a number of seconds and covert that to hours/minutes/seconds (e.g., 3456 = 00:57:36)?
â Andy Dalton
Nov 15 '16 at 14:21
yes, it is. exactly as you said.
â Vermillion
Nov 15 '16 at 14:25