Adding specific CustomLog for each Virtual Domain of Apache

for arquivo in `ls -1` ; do sed -i '/ErrorLog/a\ \ \ \ \ \ \ \ CustomLog \/var\/log\/apache2\/access_'"$file"'_log combined' /root/site-bak/${file} ; done

1
By: Gomex
2010-05-10 14:34:05

These Might Interest You

  • Outputs contents of virtual hosts containing PATTERN. Particularly useful for pefrorming complex searches. E.g. search for docroot of www.example.com: sed -n '/^[^#]*<Virtual/{:l N; /<\/Virtual/!bl;}; /www\.example\.com/p' /etc/apache2/sites-enabled/* |grep DocumentRoot Note that "Virtual" here is case sensitive. In GNU sed you may add I (capital i) modifier for case-insensitive matching: sed -n '/^[^#]*<Virtual/I{:l N; /<\/Virtual/I!bl;}; /PATTERN/p' ...


    1
    sed -n '/^[^#]*<Virtual/{:l N; /<\/Virtual/!bl;}; /PATTERN/p' vhosts.conf
    smax · 2011-02-10 02:25:49 0
  • Send apache log to syslog-ng server without change configuration of syslog. Just add in httpd.conf or vhost conf.


    1
    CustomLog "|nc -u IP PORT "<134>%{%b %d %X}t %h %l %u %t \"%r\"%>s %b \"%{Referer}i\" \"%{User-agent}i\""
    flojb · 2012-12-26 09:32:52 0
  • Ever need to know why Apache is bogging down *right now*? Hate scanning Apache's Extended server-status for the longest running requests? Me, too. That's why I use this one liner to quickly find suspect web scripts that might need review. Assuming the Extended server-status is reachable at the target URL desired, this one-liner parses the output through elinks (rendering the HTML) and shows a list of active requests sorted by longest running request at the bottom of the list. I include the following fields (as noted in the header line): Seconds: How long the request is alive PID: Process ID of the request handler State: State of the request, limited to what I think are the relevant ones (GCRK_.) IP: Remote Host IP making the request Domain: Virtual Host target (HTTP/1.1 Host: header). Important for Virtual Hosting servers TYPE: HTTP verb URL: requested URL being served. Putting this in a script that runs when triggered by high load average can be quite revealing. Can also capture "forgotten" scripts being exploited such as "formmail.pl", etc. Show Sample Output


    6
    links --dump 1 http://localhost/server-status|grep ^[0-9]|awk 'BEGIN {print "Seconds, PID, State, IP, Domain, TYPE, URL\n--"} $4 !~ /[GCRK_.]/ {print $6, $2, $4, $11, $12, $13 " " $14|"sort -n"}'
    rjamestaylor · 2009-02-19 13:06:44 2
  • The command will read the apache log file and fetch the virtual host requested and the number of requests.


    1
    cat /etc/httpd/logs/access.log | awk '{ print $6}' | sed -e 's/\[//' | awk -F'/' '{print $1}' | sort | uniq -c
    suyashjain · 2014-10-13 13:39:53 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: