[CentOS] parsing out adjacent text

Tue Jun 3 14:02:46 UTC 2014
Marios Zindilis <marios at zindilis.com>

On Tue, Jun 3, 2014 at 4:56 PM, Tim Dunphy <bluethundr at gmail.com> wrote:

> Guys,
>
>  Thank you all for your input. I can't believe how helpful this list is and
> I'm very grateful. Ok so here is what I have so far of my script to get the
> number of apache requests to a given host:
>
> #!/bin/bash
>
> # this script parses mod_status to see which hosts are getting the most
> requests
>
>
> echo “Time:”  >> /tmp/apache_request_log
>
> /usr/bin/ts >> /tmp/apache_request_log
>
> echo -e “\n” >> /tmp/apache_request_log
>
> echo “hostname”   >> /tmp/apache_request_log
>
> /bin/hostname -f  >> /tmp/apache_request_log
>
> echo -e “\n” >> /tmp/apache_request_log
>
> echo “hostname ip”   >> /tmp/apache_request_log
>
> /bin/hostname -i  >> /tmp/apache_request_log
>
> echo -e “\n” >> /tmp/apache_request_log
>
> echo “Requests per second:”  >> /tmp/apache_request_log
>
> /usr/bin/GET  http://$(/bin/hostname -i)/server-status  | /bin/grep  -i -e
> request -e requests/sec | grep -i -v -e currently  -e code  -e ss | awk
> '{print $1}' | cut -d'>' -f2  >> /tmp/apache_request_log
>
> echo “Requests processed / Idle workers:”  >> /tmp/apache_request_log
>
> /usr/bin/GET http://$(hostname -i)/server-status | /bin/grep  -i -e
> requests -e currently | grep -v -e requests/sec | cut -d'>' -f2 | cut -d'<'
> -f1  >> /tmp/apache_request_log
>
> echo -e “\n\n”  >> /tmp/apache_request_log
>
> /bin/sleep 60
>
>
>
> So now my question is, is there any way to limit the size of the output log
> from within the script without having to use logrotate? I can use that, but
> I would prefer to do that from within the script if that's possib.e
>
>
> Thanks
>
> Tim
>
>
> On Tue, Jun 3, 2014 at 9:29 AM, Patrick Bervoets <
> patrick.bervoets at psc-elsene.be> wrote:
>
> >
> > op 03-06-14 15:18, schreef Tim Dunphy:
> >
> >    [root at uszmpwslp014lc ~]# GET http://$(hostname -i)/server-status  |
> >> grep
> >> -i  requests/sec
> >> <dt>4.08 requests/sec - 80.9 kB/second - 19.8 kB/request</dt>
> >>
> >>
> >> That works ok. And next I'm grepping it back down and awking it to just
> >> the
> >> part I'm interested in:
> >>
> >> [root at uszmpwslp014lc ~]# GET http://$(hostname -i)/server-status  |
> grep
> >> -i
> >> -e request -e requests/sec | grep -i -v -e currently  -e code  -e ss |
> awk
> >> '{print $1}'
> >> <dt>4.08
> >>
> >> But now I need to get rid of just the <dt> in front of the 4.08?
> >>
> > cut --delimiter=">" --field=2
> >
> > you could even get rid of the awk and pipe your grep to cut
> > --delimiter=">" --field=2 | cut --delimiter=" " --field=1
> >
> > But there are many different ways to solve this.
> >
> > greetings
> > Patrick
> >
> >
> > _______________________________________________
> > CentOS mailing list
> > CentOS at centos.org
> > http://lists.centos.org/mailman/listinfo/centos
> >
> >
>
>
> --
> GPG me!!
>
> gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos
>



Try accessing the stats with the additional "?auto" suffix, it is meant to
be machine-readable, and is much shorter, e.g:

http://$(hostname -i)/server-status/?auto



-- 
Marios Zindilis