logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache CustomLog piped to sed
Author
dimitrov.b



Joined: 15 Dec 2017
Posts: 1
Location: UK

PostPosted: Fri 15 Dec '17 15:24    Post subject: Apache CustomLog piped to sed Reply with quote

Hello,

I'm trying to replace a pattern in access log before it is printed into the log file. I've read many articles about this but can't make it working. Tested on two different setups. Both setups were freshly installed with minimal installation and httpd installed after that.

Setup 1 - Centos 6.8 / Apache 2.2.15

CustomLog "|/bin/sed -e 's/888/111/g' >> /var/log/httpd/access_log" combined

Here it is "almost" working. Putting "$" before /bin/sed doesn't change anything. First nothing is printed into the access_log. After performing "apachectl restart" all the queries made before get printed into the log and patern 888 is replaces with 111. Any new queries are not printed until the next restart.


Setup 2 - Centos 7.3 / Apache 2.4.6

Not working at all. Without "$" before /bin/sed I'm getting error that sed can't read file ">>". With "$" there is no error but nothing is printed into access log. After restart still nothing into the log.


Many thanks!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Mon 18 Dec '17 22:50    Post subject: Reply with quote

Apache starts the standard shell to execute the command. For apache 2.2 you can also try || instead of | with the full path to sed

see
https://httpd.apache.org/docs/2.2/logs.html#piped

Yepp the 2.4 piped logs working differently

See

By default the piped log process is spawned without invoking a shell. Use "|$" instead of "|" to spawn using a shell (usually with /bin/sh -c):

So there use the $ in front of the command with the full path to sed

Make sure that sed is working correctly with the shell apache is using.
Back to top


Reply to topic   Topic: Apache CustomLog piped to sed View previous topic :: View next topic
Post new topic   Forum Index -> Apache