Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coverting Hour:Minute:Seconds to 1 day 2

Status
Not open for further replies.

viadisky

Technical User
Jun 19, 2003
110
GB
Hi,

I generated the data below from one of our network devices. Basically it's just an indication of how long a port is in it's current state.

160
0:00:19.75

The whole number "160" indicates the number of days and the "0:00:19.75" indicates H:MM:SS

Is there a one-liner awk that can convert this 0:00:19.75 to 1? This is to round it off to 1 day to allow subtraction process in later part of the script.

Any help will be appreciated.

Cheers!


 
Why don't you just add one in all cases? I mean, you're adding 1 at 19 minutes past midnight so you're rounding up under all circumstances except 00:00:00. So rounding it up under all cases will be valid except or one time in 86400 - and I'll live with a script which only fails 0.0015% of the time!

Ceci n'est pas une signature
Columb Healy
 
Hi Columb,

I tried using 0:00:19.75 in my basic computation but because it is not in a proper number format, the I get "syntax error".

Thanks for your quick reply :eek:)
 
You know the saying about great minds Annihilannic...

Ceci n'est pas une signature
Columb Healy
 
I forgot to ask, how can I add 1 to H:MM:SS? I'm looking for at least a one-liner awk or sed command ...
 
A starting point (awk):
nday=160; hms="1:23:45.67"
[!]split(hms,a,":");nday+=(a[1]/24+a[2]/144+a[3]/8640)[/!]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV, you seem to be missing a zero from your last two divisors

i.e. shouldn't it be:

nday+=(a[1]/24+a[2]/1440+a[3]/86400)
 
Thanks for the help :)

To be honest ... I'm still working out how can I incorporate your suggested one-liner awk to my script.

The original data I'm working on was generated by querying a live networking device and this device normally provides several lines at one go (depends on how many interfaces it has) ... so I can't really assign just two variables.

The example I provided above is just a portion of the big chunk of data I have. Sorry for not mentioning this in my original question.

Hope my explanation is better this time :)

I will still wait for any suggestions ...
 
Could you show us a slightly bigger chunk of your data then and the desired output for that data?

Annihilannic.
 
Hi Annihilannic,

I pasted the original data below. My main objective is to convert the first line to 1 day and the second line to 227 and the rest of the remaining lines ..

Thanks for the help :)

Cheers!

interfaces.ifTable.ifEntry.ifLastChange.5 : Timeticks: (2174985693) 0:59:39.04
interfaces.ifTable.ifEntry.ifLastChange.6 : Timeticks: (1969658578) 227 days, 23:16:25.78
interfaces.ifTable.ifEntry.ifLastChange.7 : Timeticks: (1779368614) 205 days, 22:41:26.14
interfaces.ifTable.ifEntry.ifLastChange.8 : Timeticks: (1978040465) 228 days, 22:33:24.65
interfaces.ifTable.ifEntry.ifLastChange.9 : Timeticks: (1978115174) 228 days, 22:45:51.74
interfaces.ifTable.ifEntry.ifLastChange.10 : Timeticks: (357904) 0:59:39.04
interfaces.ifTable.ifEntry.ifLastChange.11 : Timeticks: (357905) 0:59:39.05
interfaces.ifTable.ifEntry.ifLastChange.12 : Timeticks: (1923294088) 222 days, 14:29:00.88
interfaces.ifTable.ifEntry.ifLastChange.13 : Timeticks: (361120) 1:00:11.20
interfaces.ifTable.ifEntry.ifLastChange.14 : Timeticks: (2126020044) 246 days, 1:36:40.44
interfaces.ifTable.ifEntry.ifLastChange.15 : Timeticks: (2000190738) 231 days, 12:05:07.38
interfaces.ifTable.ifEntry.ifLastChange.16 : Timeticks: (903569484) 104 days, 13:54:54.84
interfaces.ifTable.ifEntry.ifLastChange.17 : Timeticks: (911551896) 105 days, 12:05:18.96
interfaces.ifTable.ifEntry.ifLastChange.18 : Timeticks: (884792877) 102 days, 9:45:28.77
interfaces.ifTable.ifEntry.ifLastChange.19 : Timeticks: (1545292845) 178 days, 20:28:48.45
interfaces.ifTable.ifEntry.ifLastChange.20 : Timeticks: (1549837080) 179 days, 9:06:10.80
 

You people can make WONDERS! Thanks a lot!!!
Next time I will post the raw data ... it will save a lot of time !!!

Cheerio!!!
 
I added the one-liner awk and my script output looks like this ...

SystemUpTime,ifLastChange,AdminStat,OperStat,DeviceName,DeviceIPAdd,InterfaceDescr
182,108,up,up,etdc1c2901,10.40.41.4,FastEthernet0/1
182,1,up,up,etdc1c2901,10.40.41.4,FastEthernet0/2
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/3
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/4
182,81,up,up,etdc1c2901,10.40.41.4,FastEthernet0/5
182,66,up,up,etdc1c2901,10.40.41.4,FastEthernet0/6
182,173,up,up,etdc1c2901,10.40.41.4,FastEthernet0/7
182,173,down,down,etdc1c2901,10.40.41.4,FastEthernet0/8

I wanted to count the interfaces which are both "down,down" or "up,down". If the interface
is in "up,down" status, I need to consider the difference between the SystemUpTime and ifLastChange (which are the first two numbers in each line). If the difference is more than 30 then I need to include that in the total count.

Sorry to be a pain again ... but for me to come up with a script which can do this it would take days ... !

Many thanks in advance :)
 
Something like this ?
awk -F, '/,up,down,/{if(($2-$1)>30)++c}/,down,down,/{++c}END{print c}' /path/to/file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

I tried using the line you provided, it didn't produce anything. The script run okay, no error message but it didn't produce any output at all. Kindly see below what I have in my server, maybe you can spot anything I missed.

Code:
zen$ cat file
182,108,up,up,etdc1c2901,10.40.41.4,FastEthernet0/1
182,1,up,up,etdc1c2901,10.40.41.4,FastEthernet0/2
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/3
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/4
182,81,up,up,etdc1c2901,10.40.41.4,FastEthernet0/5
182,66,up,up,etdc1c2901,10.40.41.4,FastEthernet0/6
182,173,up,up,etdc1c2901,10.40.41.4,FastEthernet0/7
182,173,up,up,etdc1c2901,10.40.41.4,FastEthernet0/8
182,118,up,up,etdc1c2901,10.40.41.4,FastEthernet0/9
182,118,up,up,etdc1c2901,10.40.41.4,FastEthernet0/10
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/11
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/12
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/13
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/14
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/15
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/16
182,181,up,down,etdc1c2901,10.40.41.4,FastEthernet0/17
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/18
182,1,up,up,etdc1c2901,10.40.41.4,FastEthernet0/19
182,11,up,up,etdc1c2901,10.40.41.4,FastEthernet0/20
182,11,up,up,etdc1c2901,10.40.41.4,FastEthernet0/21
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/22
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/23
182,1,up,up,etdc1c2901,10.40.41.4,FastEthernet0/24
182,1,up,down,etdc1c2901,10.40.41.4,GigabitEthernet0/1
182,1,up,down,etdc1c2901,10.40.41.4,GigabitEthernet0/2

zen$ more script
cat file | awk -F, '/,up,down,/{if(($2-$1)>30)++c}/,down,down,/{++c}END{print c}' > file.output

zen$ sh script

Many thanks :)
 
OOps, sorry for the typo :~/
awk -F, '/,up,down,/{if(([!]$1-$2[/!])>30)++c}/,down,down,/{++c}END{print c}' file > file.output

BTW what is the expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV, it worked! The expected result I'm saying is the total count of "up,down" and "down,down" interfaces, which is "8" as shown in the script output below.

This script will give me an easy way to create my Switchport Availability Report.

Thanks a million!!! :)

Code:
zen$ cat file
182,108,up,up,etdc1c2901,10.40.41.4,FastEthernet0/1
182,1,up,up,etdc1c2901,10.40.41.4,FastEthernet0/2
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/3
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/4
182,81,up,up,etdc1c2901,10.40.41.4,FastEthernet0/5
182,66,up,up,etdc1c2901,10.40.41.4,FastEthernet0/6
182,173,up,up,etdc1c2901,10.40.41.4,FastEthernet0/7
182,173,up,up,etdc1c2901,10.40.41.4,FastEthernet0/8
182,118,up,up,etdc1c2901,10.40.41.4,FastEthernet0/9
182,118,up,up,etdc1c2901,10.40.41.4,FastEthernet0/10
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/11
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/12
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/13
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/14
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/15
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/16
182,181,up,down,etdc1c2901,10.40.41.4,FastEthernet0/17
182,160,up,up,etdc1c2901,10.40.41.4,FastEthernet0/18
182,1,up,up,etdc1c2901,10.40.41.4,FastEthernet0/19
182,11,up,up,etdc1c2901,10.40.41.4,FastEthernet0/20
182,11,up,up,etdc1c2901,10.40.41.4,FastEthernet0/21
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/22
182,1,up,down,etdc1c2901,10.40.41.4,FastEthernet0/23
182,1,up,up,etdc1c2901,10.40.41.4,FastEthernet0/24
182,1,up,down,etdc1c2901,10.40.41.4,GigabitEthernet0/1
182,1,up,down,etdc1c2901,10.40.41.4,GigabitEthernet0/2

zen$ cat script
cat file | awk -F, '/,up,down,/{if(($1-$2)>30)++c}/,down,down,/{++c}END{print c}' > file.output

zen$ sh script

zen$ cat file.output
8
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top