Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Apr 2007 09:28:45 -0500
From:      Derek Ragona <derek@computinginnovations.com>
To:        Gary Kline <kline@tao.thought.org>
Cc:        Rick Olson <rick@napalmriot.com>, Gary Kline <kline@tao.thought.org>, FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: awk question
Message-ID:  <6.0.0.22.2.20070411092614.025752d8@mail.computinginnovations.com>
In-Reply-To: <20070411004319.GC35246@thought.org>
References:  <20070306003506.GA12553@thought.org> <6.0.0.22.2.20070306072709.02577448@mail.computinginnovations.com> <20070306165349.GA67829@thought.org> <461AEE3F.2010107@napalmriot.com> <20070410231701.GA35246@thought.org> <6.0.0.22.2.20070410183124.024f8b10@mail.computinginnovations.com> <20070411004319.GC35246@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
At 07:43 PM 4/10/2007, Gary Kline wrote:
>On Tue, Apr 10, 2007 at 06:35:33PM -0500, Derek Ragona wrote:
> > At 06:17 PM 4/10/2007, Gary Kline wrote:
> > >On Mon, Apr 09, 2007 at 06:54:07PM -0700, Rick Olson wrote:
> > >> I'm assuming you've already taken care of this, but to answer your
> > >> original question in AWK form, you could have done the following:
> > >>
> > >> ls -l | awk '$8 == 2006 {system("rm " $9)}'
> > >>
> > >
> > >        i'Ll save your snippet to my growing %%% awk file in my ~/HowTo,
> > >        thankee much.  I'm in the first stages on a months-long trial on
> > >        system tuning.  This, before I'd risk publishing anything.  So
> > >        far tho, by upping and lower the NICE prio of various binaries, I
> > >        have been able to get more than 70% efficient use out of my older
> > >        servers.  ---This *ought* to carry over to my faster machines....
> > >
> > >        Is tthere a way of using ps -alx | ask to look at nice and if it
> > >        is non-zero (the default), to reset it to zero?
> >
> > You can easily do some of this using top, such as:
> > top -bS 200 | tail -n +9 | awk '{ print $5 }'
> >
> > If you want to tweak the nice value you'd need to examine the value and
> > then renice it as long as you are root.  You'd need the PID for that, so
> > here's another example:
> > top -bS 200 | tail -n +9 | awk '{ printf("Pid: %d has Nice: %d\n", 
> $1,$5) }'
> >
>
>         Well, I knew there had to be a "static" way to read top.  -bS is
>         it.  If NICE is 9, then renice-n -9 pid ought to reset it to 0;
>         so in C, the check for nice or "n" would be trivial:
>
>         if (n != 0)
>                 n = -n;
>
>         In you example, would this be if ($1 != 0) $1 = -$1;
>         then a '{system("renice -n $")};
>         or is this disallowed in awk?
>
>         gary

It is easier to redirect the output to a file then just execute that 
file.  You'd usually have this in a shell script run by cron.

top -bS 200 | tail -n +9 | awk '{ if ($1 != 0) printf("/usr/bin/renice %d 
%d\n", $1,-$5) }' > /tmp/renice.scr
sh -c /tmp/renice.scr

But look at the file generated, you need to do more than just the check for 
0 and then negate it.

         -Derek

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6.0.0.22.2.20070411092614.025752d8>