Re: Need a script to get load (553 Views)
Reply
Occasional Visitor
Derek_59
Posts: 4
Registered: ‎06-15-2004
Message 1 of 12 (553 Views)

Need a script to get load

right now I am using w to get the load running it every 5mins.

What I want is to just filter out the load numbers and paste that into a certain spot in an html file.

Is there a way I can do this?

Derek
Honored Contributor
Bharat Katkar
Posts: 2,309
Registered: ‎05-29-2003
Message 2 of 12 (553 Views)

Re: Need a script to get load

Derek,
Is this what you are looking for:

#!/usr/bin/ksh
while true
do
echo `w -u' >> filename
sleep 300
done

Regards,

You need to know a lot to actually know how little you know
Honored Contributor
Bharat Katkar
Posts: 2,309
Registered: ‎05-29-2003
Message 3 of 12 (553 Views)

Re: Need a script to get load

Derek,

echo `w -u' >> filename

This line has back quotes `w -u`

regards,


You need to know a lot to actually know how little you know
Honored Contributor
Mark Grant
Posts: 2,712
Registered: ‎04-01-2003
Message 4 of 12 (553 Views)

Re: Need a script to get load

Well here's a sily way of doing it

$LOAD=`uptime | cut -c45- | sed "s/,//g"`
Never preceed any demonstration with anything more predictive than "watch this"
Occasional Visitor
Derek_59
Posts: 4
Registered: ‎06-15-2004
Message 5 of 12 (553 Views)

Re: Need a script to get load

Mark,

That is almost there, it is cuttin the word Load off before average. what can we do to keep that there?

Derek
Honored Contributor
Mark Grant
Posts: 2,712
Registered: ‎04-01-2003
Message 6 of 12 (553 Views)

Re: Need a script to get load

reduce the number 45 until it chops off the correct number of characters. On my system that is 25.
Never preceed any demonstration with anything more predictive than "watch this"
Occasional Visitor
Derek_59
Posts: 4
Registered: ‎06-15-2004
Message 7 of 12 (553 Views)

Re: Need a script to get load

sweet, now I will just do an SSI to insert it into an html page.

Thanks to both of you!
Honored Contributor
Geoff Wild
Posts: 7,170
Registered: ‎06-04-2001
Message 8 of 12 (553 Views)

Re: Need a script to get load

And now for something completely different - a man with awk:

uptime | awk '{print $10, $11, $12}' |sed s/,//g

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Honored Contributor
Bill Hassell
Posts: 14,205
Registered: ‎05-29-2000
Message 9 of 12 (553 Views)

Re: Need a script to get load

After years of scripting, I try to stay away from cut -c because the column numbers do not remain stable on many commands and cut's -d does not understand white space as a field (cut -d " " counts every space as a separate field). Geoff's solution is the most stable since changes to the number of spaces between fields can change but awk will always extract fields 10,11,12.
Valued Contributor
rmueller58
Posts: 851
Registered: ‎02-19-2001
Message 10 of 12 (553 Views)

Re: Need a script to get load

I'm with Bill,
Just use awk to strip the fields you need, you can use head or tail to remove the header information.
Honored Contributor
Mark Grant
Posts: 2,712
Registered: ‎04-01-2003
Message 11 of 12 (553 Views)

Re: Need a script to get load

I'm with Bill too. This is the reason I called it a "silly" way but I obviously can't spell "silly" properly :)
Never preceed any demonstration with anything more predictive than "watch this"
Occasional Visitor
Derek_59
Posts: 4
Registered: ‎06-15-2004
Message 12 of 12 (553 Views)

Re: Need a script to get load

Thanks to all. works perfect with awk!
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.