Operating System - HP-UX
1748088 Members
4995 Online
108758 Solutions
New Discussion юеВ

Re: Need a script to get load

 
Derek_59
New Member

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 11
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
New Member

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
New Member

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.