Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Jan 152010
 

Sending Apache log to syslog?

Answer:

In the Apache config (httpd.conf), add/modify the followings as needed

1. For Access log

CustomLog |/usr/local/apache/bin/apache_syslog combined

Where apache_syslog is a Perl script


#!/usr/bin/perl
use Sys::Syslog qw( :DEFAULT setlogsock );

setlogsock('unix');
openlog('apache', 'cons', 'pid', 'local2');

while ($log = ) {
            syslog('notice', $log);
}
closelog

2. For Error log

Apache already has direct support error log to syslog, so just add the target syslog facility.

ErrorLog syslog:local1

This tells Apache to send the error log output to the syslog facility local1

Jan 132010
 

How to split a large file into multiple smaller files in Linux

Answer:

If you have a very large file and want to split into multiple smaller files, split command can do the job for you.

# split -l 10 text.txt

The above command split the file text.txt into a multiple files (xaa, xab, xac...), which contains at most 10 lines per file.

Jan 132010
 

Read command line arguments in Perl

Answer:

To read the command line arguments in Perl, you need to play with the special array $ARGV

E.g. test.pl

#!/usr/bin/perl
use strict;

print $ARGV[0];

Then execute

# perl test.pl hello
hello

The first argument will be printed to the screen.