Linux Uptime

Linux Uptime

am 17.12.2010 02:32:43 von matt

I have a perl script but I want to exit it if the uptime on the server
is less then say an hour. Any idea how I would get uptime with perl?

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Linux Uptime

am 17.12.2010 02:48:57 von Sheppy R

--20cf30564475a625c00497915f36
Content-Type: text/plain; charset=ISO-8859-1

http://search.cpan.org/~burak/Sys-Info-Base-0.73/lib/Sys/Inf o/OS.pm#uptime

Sys::Info::OS has an uptime() method.

On Thu, Dec 16, 2010 at 8:32 PM, Matt wrote:

> I have a perl script but I want to exit it if the uptime on the server
> is less then say an hour. Any idea how I would get uptime with perl?
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--20cf30564475a625c00497915f36--

Re: Linux Uptime

am 17.12.2010 03:25:41 von Jeff Peng

于 2010-12-17 9:32, Matt 写道:
> I have a perl script but I want to exit it if the uptime on the server
> is less then say an hour. Any idea how I would get uptime with perl?

$ cat /proc/uptime
4205976.64 4017280.59

The first column is the host's uptime seconds.

Jeff.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Linux Uptime

am 17.12.2010 03:26:53 von Jim Gibson

At 7:32 PM -0600 12/16/10, Matt wrote:
>I have a perl script but I want to exit it if the uptime on the server
>is less then say an hour. Any idea how I would get uptime with perl?

On Unix:

my $uptime = qx(uptime);

Then parse $uptime with a regular expression, which may depend upon
what your version of uptime outputs :

if( $uptime =~ /up (\d+s+\w+)/ ) {
print "$1\n";
}


--
Jim Gibson
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Linux Uptime

am 17.12.2010 04:21:54 von Katie T

On Fri, Dec 17, 2010 at 2:25 AM, Jeff Peng wrote:
> äº=8E 2010-12-17 9:32, Matt 写道:
>>
>> I have a perl script but I want to exit it if the uptime on the server
>> is less then say an hour.  Any idea how I would get uptime with per=
l?
>
> $ cat /proc/uptime
> 4205976.64 4017280.59
>
> The first column is the host's uptime seconds.

/proc/uptime is a linux innovation I believe, other *nix variant may
not have it (I don't think Solaris does).

Katie
--=20
CoderStack
http://www.coderstack.co.uk/perl-jobs
The Software Developer Job Board

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Linux Uptime

am 17.12.2010 04:28:56 von Katie T

On Fri, Dec 17, 2010 at 3:21 AM, Katie T wrote:
> On Fri, Dec 17, 2010 at 2:25 AM, Jeff Peng wrote:
>> äº=8E 2010-12-17 9:32, Matt 写道:
>>>
>>> I have a perl script but I want to exit it if the uptime on the server
>>> is less then say an hour.  Any idea how I would get uptime with pe=
rl?
>>
>> $ cat /proc/uptime
>> 4205976.64 4017280.59
>>
>> The first column is the host's uptime seconds.
>
> /proc/uptime is a linux innovation I believe, other *nix variant may
> not have it (I don't think Solaris does).

d'oh just read the subject line. ignore me.

Katie
--=20
CoderStack
http://www.coderstack.co.uk/perl-jobs
The Software Developer Job Board

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Linux Uptime

am 17.12.2010 04:29:44 von Shawn H Corey

On 10-12-16 10:21 PM, Katie T wrote:
> /proc/uptime is a linux innovation I believe, other *nix variant may
> not have it (I don't think Solaris does).

The /proc directory is a pseudo-directory that the kernel maintains.
Every "file" in it is a pipe that can be read using regular file
handles. And I believe only Linux does this.


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Linux Uptime

am 17.12.2010 05:17:37 von Jeff Peng

于 2010-12-17 11:29, Shawn H Corey 写道:
> Every "file" in it is a pipe that can be read using regular file
> handles. And I believe only Linux does this.

Yep.Also the OP is asking exactly about linux.

--
Jeff Peng
jeffpeng@gmx.net

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Linux Uptime

am 17.12.2010 06:30:53 von Alan Haggai Alavi

Matt wrote:

> I have a perl script but I want to exit it if the uptime on the
server
> is less then say an hour. Any idea how I would get uptime with
perl?


Hi,

You could use the distribution: Unix::Uptime
(http://search.cpan.org/perldoc?Unix::Uptime)

Example:

use strict;
use warnings;

use Unix::Uptime;

my $uptime_hours = Unix::Uptime->uptime() / 3600;
if ( $uptime_hours < 1 ) {
exit(127);
}

Regards,
Alan Haggai Alavi.
--
The difference makes the difference.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/