Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Need a script to get load

Occasional Visitor

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
11 REPLIES
Honored Contributor Honored Contributor

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 Honored Contributor

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 Honored Contributor

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

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 Honored Contributor

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

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 Honored Contributor

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.
Highlighted
Honored Contributor Honored Contributor

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 Valued Contributor

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 Honored Contributor

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

Re: Need a script to get load

Thanks to all. works perfect with awk!