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
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
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 )
thanks for your reply ,pludi
my os is HP UX 11.31
when I test
this command
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";'
I only get the current time
not how long system has been boot time at
YYYY-MM-DD hh:mm
thanks
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
my test result
command:uptime
show 4:15pm up 21:36, 2 users, load average: 0.00, 0.00, 0.00
run:
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";'
result:Fri Apr 17 16:16:50 2009
command:date
Fri Apr 17 16:17:22 EAT 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)
I'm sorry I didn's say clear
it work thanks pludi
i found another way use pstat_static