Home > Archive > AWK > February 2005 > Checking uptime if greater than 10 minutes.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Checking uptime if greater than 10 minutes.
|
|
| richardkreidl@northwesternmutual.com 2005-02-20, 3:55 pm |
| I need to write a script that will check the 'uptime' of a server that
has just been rebooted. If the uptime is greater than 10 minutes do
something otherwise do something else.
The awk statement below works when the format is like this:
9:13pm up 430 days, 0:09, 2 users, load average: 0.00, 0.00, 0.00
uptime | awk '/day/{exit 1}($3~/0:0/){exit 0}{exit 1}' && echo do_this
|| echo do_else
But, when the format is like this the awk statement doesn't work:
08:36AM up 6 mins, 1 user, load average: 0.12, 0.15, 0.07
Thanks
| |
| Kenny McCormack 2005-02-20, 3:55 pm |
| In article <1108913966.175531.235650@c13g2000cwb.googlegroups.com>,
richardkreidl@northwesternmutual.com <richardkreidl@northwesternmutual.com> wrote:
>I need to write a script that will check the 'uptime' of a server that
>has just been rebooted. If the uptime is greater than 10 minutes do
>something otherwise do something else.
>
>The awk statement below works when the format is like this:
>9:13pm up 430 days, 0:09, 2 users, load average: 0.00, 0.00, 0.00
>
>uptime | awk '/day/{exit 1}($3~/0:0/){exit 0}{exit 1}' && echo do_this
>|| echo do_else
>
>But, when the format is like this the awk statement doesn't work:
>08:36AM up 6 mins, 1 user, load average: 0.12, 0.15, 0.07
Which OS?
| |
| Patrick TJ McPhee 2005-02-21, 3:55 am |
| In article <1108913966.175531.235650@c13g2000cwb.googlegroups.com>,
richardkreidl@northwesternmutual.com <richardkreidl@northwesternmutual.com> wrote:
[...]
% The awk statement below works when the format is like this:
% 9:13pm up 430 days, 0:09, 2 users, load average: 0.00, 0.00, 0.00
%
% uptime | awk '/day/{exit 1}($3~/0:0/){exit 0}{exit 1}' && echo do_this
% || echo do_else
%
% But, when the format is like this the awk statement doesn't work:
% 08:36AM up 6 mins, 1 user, load average: 0.12, 0.15, 0.07
I suggest looking at the data in the output and figuring out what to
do from there. For instance, on my system, uptime gives output like
this when the uptime is < 1 hour:
8:33PM up 33 mins, 4 users, load averages: 0.00, 0.22, 0.38
I would look for this line and check the value of $3 in this case:
$4 ~ /^min/ && $3 < 10 { exit 0 }
{ exit 1}
If your output is different from that, you need to figure out what
it's like in the cases which interest you and look for those lines.
--
Patrick TJ McPhee
North York Canada
ptjm@interlog.com
| |
| Bill Marcum 2005-02-21, 8:55 am |
| On 20 Feb 2005 07:39:26 -0800, richardkreidl@northwesternmutual.com
<richardkreidl@northwesternmutual.com> wrote:
> I need to write a script that will check the 'uptime' of a server that
> has just been rebooted. If the uptime is greater than 10 minutes do
> something otherwise do something else.
>
> The awk statement below works when the format is like this:
> 9:13pm up 430 days, 0:09, 2 users, load average: 0.00, 0.00, 0.00
>
> uptime | awk '/day/{exit 1}($3~/0:0/){exit 0}{exit 1}' && echo do_this
>|| echo do_else
>
> But, when the format is like this the awk statement doesn't work:
> 08:36AM up 6 mins, 1 user, load average: 0.12, 0.15, 0.07
>
$4~/min/ && $3<10{exit 0}
|
|
|
|
|