Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Need a script to get load

Derek_59
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
Bharat Katkar
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
Bharat Katkar
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
Mark Grant
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"
Derek_59
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
Mark Grant
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"
Derek_59
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!
Geoff Wild
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.
Bill Hassell
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.


Bill Hassell, sysadmin
rmueller58
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.
Mark Grant
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"
Highlighted
Derek_59
Occasional Visitor

Re: Need a script to get load

Thanks to all. works perfect with awk!