Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

linux boot time

by da w00t (Sexton)
on May 15, 2000 at 13:58 UTC ( [id://11582]=CUFP: print w/replies, xml ) Need Help??

Wanna know the boot time of a linux box? It's stored in /proc/stat, for easy use, in the standard unix time format. Here's a 1 liner to print it out, in your local timezone.
open P,"/proc/stat";undef $/;$c=<P>;($t)=($c =~ /btime\s(\d+)/);print +localtime($t)."\n";

Replies are listed 'Best First'.
RE: linux boot time
by merlyn (Sage) on May 15, 2000 at 21:49 UTC
      Easier yet with sed and date:
      date -d @$(sed -n '/^btime /s///p' /proc/stat)
      (OK, there's no Perl here, but that was just for the thrill of "improving" upon a Randal L. Schwartz solution :)
        My "date" here doesn't have a "-d" that works that way. Nor is @$(...) standard. I suspect you're coding full of linuxisms without realizing it, although in this context, it's fair since it was about a "linux" boot time.

        -- Randal L. Schwartz, Perl hacker

        The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://11582]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found