Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Uptime question (Unix-related)



John Mundt wrote:

On Feb 14, 2007, at 14:18, Nick McSpadden wrote:

This is really more of a UNIX question than an ARD question, so sorry if this is off topic.

I want to set up a repeated job on the macs that checks their load average and then performs certain tasks based on that. It's easy enough to do load average checking with the UNIX command "uptime."

I know I can get the load average amount with the UNIX command:
uptime | cut -c 48-49
(so if the load average is 0.18, I'll get 18 as the number).

I then want to test this against a threshold amount, such as 40 (i.e. if load average goes above 0.4):

In a UNIX shell script, i can set this to:


#!/bin/bash let LAVG=`uptime | cut -c 48-49` let THRESHOLD=40 if ( $LAVG > $THRESHOLD) then <do stuff....> else <do something else....> fi

I get a different location for uptime, so I modified the LAVG line. BTW, if your load average goes up over 0.99, you'd not see the whole number.



#!/bin/bash LAVG=`uptime | cut -c 48-49` LAVG=`uptime` LAVG=`expr "$LAVG" : '.*\: [^\.]*\.\(..\)'` THRESHOLD=40 if [ "$LAVG" -gt $THRESHOLD ] then # <do great things> echo do else # <do lesser things> echo do not fi

John


--------------------------------------------------------------------------


"They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety."
---- Benjamin Franklin
--------------- "Dotage," Beneteau 373 -----------------
John P. Mundt Network Manager
Hawthorn District 73 email@hidden
Vernon Hills, IL 60061 847-990-4591




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Remote-desktop mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/remote-desktop/email@hidden



This email sent to email@hidden
I'd advise that both of you stop using cut for these types of tasks. Also, going directly to the proc for information when relevant is a preferred method. If this was to be executed on a Linux machine you'd want to use: awk '{gsub(/\./,"");print$1}' /proc/loadavg

If your uptime changes into more days than you have allowed for then your cut script will error. 48 characters is great for the single digit days of uptime, but what about when your server gets into triple digits? Taking directly from the proc and using the correct columns is the way to go.

--
- Ken Garland
- Systems Administrator
- Rotech Healthcare, Inc.
- 321.235.3100 x 2042

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Remote-desktop mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/remote-desktop/email@hidden

This email sent to email@hidden
References: 
 >Killing Applications using ARD (From: Theresa Bright <email@hidden>)
 >Re: Killing Applications using ARD (From: "Robert Jacobson" <email@hidden>)
 >Uptime question (Unix-related) (From: Nick McSpadden <email@hidden>)
 >Re: Uptime question (Unix-related) (From: John Mundt <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.