- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- False NTP, how to compare 2 time stamps?
Operating System - HP-UX
1753510
Members
5541
Online
108795
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2004 06:55 AM
тАО03-19-2004 06:55 AM
I need to figure out a script to determine how many seconds two time stamps are apart. I am writing a script in HP-UX POSIX shell but am willing to try other languages if the task is better suited.
Easy example ( 31 seconds difference )
14:45:32
14:45:01
Hard example: ( 31 seconds differnce )
23:59:01
00:00:29
Any ideas or assistance would be appreciated. Here's the short answer to "why." My MPE/iX admins can't or won't install NTP on our HP3000 servers so I wrote and Expect script that telnets to MPE and retreives the system time. I can then compare that to the current system (Unix ) time. I simply want to know if they are more than 1 minute apart, then I'll generate an HP Openview and/or email alert so we know to set the system time asap.
Of course, points will be awarded.
Easy example ( 31 seconds difference )
14:45:32
14:45:01
Hard example: ( 31 seconds differnce )
23:59:01
00:00:29
Any ideas or assistance would be appreciated. Here's the short answer to "why." My MPE/iX admins can't or won't install NTP on our HP3000 servers so I wrote and Expect script that telnets to MPE and retreives the system time. I can then compare that to the current system (Unix ) time. I simply want to know if they are more than 1 minute apart, then I'll generate an HP Openview and/or email alert so we know to set the system time asap.
Of course, points will be awarded.
Solved! Go to Solution.
- Tags:
- NTP
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2004 06:58 AM
тАО03-19-2004 06:58 AM
Re: False NTP, how to compare 2 time stamps?
forgive the typo.. I'm aware that the times are not 31 seconds apart but you get the idea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2004 07:16 AM
тАО03-19-2004 07:16 AM
Solution
Note: Your second example is wrong; shpould be 88 seconds.
First if you have Perl on your MPE box then this is trivially simple:
try
perl -e 'print scalar time'
That will yield epoch seconds gives you values you can readily subtract -- regardless of timezones.
Plan B: Pure shell but I assume you can parse HH:MM:SS into 3 distinct variables
#!/usr/bin/sh
seconds()
{
typeset -i10 HR=${1}
typeset -i10 MIN=${2}
typeset -i10 SEC=${3}
shift 3
typeset -i10 TM=$(( (${HR} * 3600) + (${MIN} * 60) + ${SEC} ))
echo "${TM}"
return 0
} # seconds
typeset -i10 DIFF=0
typeset -i10 T1=$(seconds 23 59 01)
typeset -i10 T2=$(seconds 00 00 29)
if [[ ${T1} -gt ${T2} ]]
then
DIFF=$(( (86400 - ${T1}) + ${T2} ))
else
DIFF=$(( ${T2} - ${T1} ))
fi
echo "Diff = ${DIFF} seconds."
If I ain't made no typo's that should do it but it only allows for 1 day's wraparound and does assume that both times are same timezone.
First if you have Perl on your MPE box then this is trivially simple:
try
perl -e 'print scalar time'
That will yield epoch seconds gives you values you can readily subtract -- regardless of timezones.
Plan B: Pure shell but I assume you can parse HH:MM:SS into 3 distinct variables
#!/usr/bin/sh
seconds()
{
typeset -i10 HR=${1}
typeset -i10 MIN=${2}
typeset -i10 SEC=${3}
shift 3
typeset -i10 TM=$(( (${HR} * 3600) + (${MIN} * 60) + ${SEC} ))
echo "${TM}"
return 0
} # seconds
typeset -i10 DIFF=0
typeset -i10 T1=$(seconds 23 59 01)
typeset -i10 T2=$(seconds 00 00 29)
if [[ ${T1} -gt ${T2} ]]
then
DIFF=$(( (86400 - ${T1}) + ${T2} ))
else
DIFF=$(( ${T2} - ${T1} ))
fi
echo "Diff = ${DIFF} seconds."
If I ain't made no typo's that should do it but it only allows for 1 day's wraparound and does assume that both times are same timezone.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2004 07:19 AM
тАО03-19-2004 07:19 AM
Re: False NTP, how to compare 2 time stamps?
Get the epoch time using perl etc. and do some mathes to know the difference in seconds.
Such as
perl -e 'print time(), "\n"'
This will print time in epoch
then
echo "epoch_time_1-epoch_time_2"|bc
Hope this helps.
Anil
Such as
perl -e 'print time(), "\n"'
This will print time in epoch
then
echo "epoch_time_1-epoch_time_2"|bc
Hope this helps.
Anil
There is no substitute to HARDWORK
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP