I wish to dump the output of rsyslog(service) to some file at a selected
location.
Following is what I have tried :
1. Made changes to /etc/rsyslog.conf
#################
#### MODULES ####
#################
$ModLoad imfile
$ModLoad omprog <----- NEWLY ADDED ------>
$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog # provides kernel logging support
#$ModLoad immark # provides --MARK-- message capability
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$ActionOMProgBinary /home/test/dmsg <----- NEWLY ADDED ------>
# Filter duplicated messages
dmsg : Is a C program that reads the lines from stdin and writes it to
file (/home/test/log_syslog_file)
I am expecting the output to be dumped to /home/test/log_syslog_file
But nothing happens.
code for dmsg (dmsg.c) ::
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
int main(){
char* lineptr;
size_t size = 0;
int fd = open("log_syslog_file", O_CREAT| O_WRONLY);
while(getline(&lineptr, &size, stdin)>0){
if(write(fd, lineptr, strlen(lineptr))<0){
fprintf(stderr, "write failure");
break;
}
}
free(lineptr);
close(fd);
return 0;
}
I am using Ubuntu 14.04
-------- EDIT ---------
After starting the rsyslog service,
I am giving the following command:
rsyslogd -c5 -d -n
When I use the following it works fine :
cat /var/log/syslog | ./dmsg
Thanks.