I want to get machine boot up time

Thread Tools Search this Thread
Operating Systems HP-UX I want to get machine boot up time
# 1  
Old 04-17-2009
I want to get machine boot up time

I use the uptime command,but

it only show how long system has been up
up 18 days
but I want the this format
machine boot time YYYY-MM-DD hh:mm:ss

does any command can get that or how to i use program to do this
# 2  
Old 04-17-2009
This could help:
uptime | \
perl -ne '/.*up (\d+) days, +(\d+):(\d+),.*/; $total=((($1*24+$2)*60+$3)*60);
$now=time(); $now-=$total; $now=localtime($now); print $now,"\n";'

It's not exact to the second, since uptime looses that information, but it's probably close enough.

Not relating to your problem, just in case anyone needs such a command for Linux:
date -d @$( awk "{print \"$(date +%s)-$1\"}" /proc/uptime )

Last edited by pludi; 04-17-2009 at 04:37 AM..
# 3  
Old 04-17-2009
thanks for your reply ,pludi

my os is HP UX 11.31
when I test
this command
uptime | \
perl -ne '/.*up (\d+) days, +(\d+)Smilie\d+),.*/; $total=((($1*24+$2)*60+$3)*60);
$now=time(); $now-=$total; $now=localtime($now); print $now,"\n";'

I only get the current time
not how long system has been boot time at
YYYY-MM-DD hh:mm

# 4  
Old 04-17-2009
That's strange. I just fed it to our HP-UX 11.31 (IA64), using Perl 5.8.8, and it works correctly.
$ uptime
  9:14am  up 156 days, 20:52 ...
$ uptime | \
perl -ne '/.*up (\d+) days, +(\d+):(\d+),.*/; $total=((($1*24+$2)*60+$3)*60);
$now=time(); $now-=$total; $now=localtime($now); print $now,"\n";'
Tue Nov 11 11:21:43 2008

# 5  
Old 04-17-2009
my test result
show 4:15pm up 21:36, 2 users, load average: 0.00, 0.00, 0.00

uptime | \
perl -ne '/.*up (\d+) days, +(\d+)Smilie\d+),.*/; $total=((($1*24+$2)*60+$3)*60);
$now=time(); $now-=$total; $now=localtime($now); print $now,"\n";'

result:Fri Apr 17 16:16:50 2009
Fri Apr 17 16:17:22 EAT 2009
# 6  
Old 04-17-2009
You never said that your system hasn't even been up for a day (your first post even implied [to me] that it's been up at least 18 days). Try this:
uptime | \
perl -ne '/.*up +(?:(\d+) days?,? +)?(\d+):(\d+),.*/; $total=((($1*24+$2)*60+$3)*60);
$now=time(); $now-=$total; $now=localtime($now); print $now,"\n";'

It should work even if the system hasn't been up for a day (don't have a system to test on)

Last edited by pludi; 04-17-2009 at 06:56 AM..
# 7  
Old 04-18-2009
I'm sorry I didn's say clear

it work thanks pludi

i found another way use pstat_static
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

CentOS machine does not boot!

Hello, one of my machine ,does not boot! check the pic and kindly help! Thx in advance! (0 Replies)
Discussion started by: ahmedamer12
0 Replies

2. Solaris

After command setenv auto-boot false machine's console not displaying

hi Alll, I want to install solaris 10 on exixting solaris mahcine. I tried for OK boot cdrom-install but it gave me fatal error - disk not bootable , boot command disable so i tried with ok setenv auto-boot? false Ok reset-all after this server rebooted automatically and... (2 Replies)
Discussion started by: sunray
2 Replies

3. Ubuntu

What time did Ubuntu installed on machine?

How can I learn what time OS installed time and release information. (4 Replies)
Discussion started by: getrue
4 Replies

4. UNIX and Linux Applications

How do I Start postgre SQL automatically when boot my linux machine

Can any body give me the script to start postgre SQL 8.3.1 when boot linux? (2 Replies)
Discussion started by: shiraz
2 Replies

5. Shell Programming and Scripting

How do I Start JBoss automatically when boot my linux machine.

I have created a script file named 'start-jboss' ------------------------------------------------- #!/bin/sh # For starting Jboss JAVA_HOME=/home/argole/jdk/jdk1.6.0_10 export JAVA_HOME cd /home/argole/server/jboss-4.2.0.GA/bin echo "Starting JBOSS server" nohup ./run.sh -c... (25 Replies)
Discussion started by: shiraz
25 Replies

6. Solaris

Sun machine boot up

Hi I am trying to bring up our Sun V100 machine remotely using hyper terminal. We have connected LOM port A to COM1 of our windows server and have lom promt available. Now when we type poweron it starts booting and goes through the booting process and stops at the following step... .... ... (7 Replies)
Discussion started by: chimpu
7 Replies

7. UNIX for Dummies Questions & Answers

Cannot boot machine

I have a sun v240 running solaris 9. I recently changed the ip via the ifconfig command but made a mistake when running the command: ifconfig bge0 (ip address) netmask (ip address) when i meant to do: ifconfig bge0 (ip address) netmask ffff0000 broadcast (ip address) Now when I boot the... (4 Replies)
Discussion started by: GLJ@USC
4 Replies

8. UNIX for Dummies Questions & Answers

Triple Boot Machine

I'm in a predicament right now! I have RedHat 7.2 ,Debian 2.2r5 ,and Windows ME. I am currently in a Sun Solaris 8 class and will soon acquire a copy of Solaris 8. I would like to start a small home network ,but 4 pc's for the house would be a little too expensive for me right now. What I was... (4 Replies)
Discussion started by: bilal_aa
4 Replies
Login or Register to Ask a Question

Featured Tech Videos