How to convert seconds to hh:mm:ss format from output of another shell script

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question





















  • 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














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.










share|improve this question





















  • 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












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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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





share|improve this answer






















  • 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


















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





share|improve this answer




















  • thanks man. but it doesn't work for me. but I do appreciate your help!
    – Vermillion
    Nov 15 '16 at 14:40










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%2f323429%2fhow-to-convert-seconds-to-hhmmss-format-from-output-of-another-shell-script%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



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





share|improve this answer






















  • 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















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





share|improve this answer






















  • 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













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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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













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





share|improve this answer




















  • thanks man. but it doesn't work for me. but I do appreciate your help!
    – Vermillion
    Nov 15 '16 at 14:40














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





share|improve this answer




















  • thanks man. but it doesn't work for me. but I do appreciate your help!
    – Vermillion
    Nov 15 '16 at 14:40












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





share|improve this answer












#!/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






share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

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

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?