Want to get /var/log/messages redirected to a FIFO ...


 
Thread Tools Search this Thread
Top Forums Programming Want to get /var/log/messages redirected to a FIFO ...
# 1  
Old 12-28-2008
Data Want to get /var/log/messages redirected to a FIFO ...

Is it possible that I get all the syslog messages from /var/log/messages redirected to some FIFO as and when any new messages comes.

In exact, I need to duplicate the messages to a FIFO, the moment a new message is logged; from where another process reads and does some processing without affecting the /var/log/messages file and normal loging process.

Is this possible that we hook somehow /dev/log socket and get a copy of the messages there itself ?

I tried this (this would be the most preffered way for me) but in vein.

Otherwise is this possible using dup2() on /var/log/messages itself and redirect to some FIFO, then a child process will always read from FIFO for newer messages? My program will have the root access.

A sample C program would be the best.

Thanks in advance to everyone for any kind of advice.

Last edited by Praveen_218; 12-28-2008 at 03:43 PM.. Reason: Some edition to the text.
# 2  
Old 12-29-2008
this should do it.

shutdown syslogd
mv /var/log/messages /var/log/messages.old
mkfifo /var/log/messages
start process to read the /var/log/messages fifo
start syslogd
# 3  
Old 12-29-2008
But with this approach, 'cat /var/log/messages ' won't work.

I tried creating a FIFO somewhere and then openned both. Openned FIFO in write mode and the file /var/log/messages in a read mode and then tried using dup2(FIFO_fd, message_fd).

Created another process and opened FIFO in the read mode an waited for data; didn't work out at all.
# 4  
Old 12-29-2008
Bug A C program to do the job

I send you a cpio file with the sources and the Makefile to produce an executable to do the job. I believe you know cpio and how to run make. The steps are:

Login as root.
Run cpio:
cpio -icdm <logck.txt
cd logck
Edit Makefile (replace EXEC = logck with the name you want, e.g.
EXEC = /usr/bin/logck)
Run make
Run the program, e.g.
/usr/bin/logck /var/log/messages >/var/log/logck.out 2>/var/log/logck.err

Note that there is no need for backgrounds or nohups, everything is controlled via signal and fork calls. Please read the sources. The default polling interval is 2 seconds, but you can increase with -s option.
# 5  
Old 12-30-2008
HI Panos.
Thank you very much for the code.
The code is working.
But wouldn't it be a performance issue as the code is performing a lot of fopen() after it sees the file_size changes before closing and then reopening and fseek() to point to additional new data?

In the meanwhile, I had followed up the 'tail' utility code and had a kind of similar approached but used nanosleep() and then fstat() in a loop to adjudge the file_size before lseek() to point to the new data in the file.

In all your code worked to a great extent for me Smilie

Ya one another thing is that the file (was the SVR4 cpio archive having no CRC) and had a problem on my FreeBSD7 machine (I use it for multipurpose --one being a file server for me through samba connection, so all new UNIX file first go there before it goes on any other machine from my desktop).

It reported me an error like "cpio: premature end of file".
When I transfered the same to a RedHatLinux machine, it worked and extracted the directory Smilie

However the code was compiling and running on both machines but the output was taking time and strace and truss had problem attaching the executable, partially, I hope due to ignoring almost all the signal (installed earlier in the code).
# 6  
Old 12-30-2008
Praveen,

I don't know if this is related to your problem but have you explore the /etc/syslog.conf or related settings to syslog? You can specify to a location to where you want to store the capture logs.

Cheers
# 7  
Old 12-30-2008
Quote:
Originally Posted by csorhand
Praveen,

I don't know if this is related to your problem but have you explore the /etc/syslog.conf or related settings to syslog? You can specify to a location to where you want to store the capture logs.

Cheers
Right, and that "location" can also be (1) another program, (2) another host, (3) another file which is a named pipe.

If the mkfifo didn't work for you, keep in mind, the data can be read *only* once.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Meaning of /var/log/messages

I am getting a lot of message as follows in /var/log/message files as follows. messages.1:559:May 4 20:01:56 SERVER2 kernel: session_stat: sync=0 async=33 aretr=0 messages.1:560:May 4 20:02:42 SERVER2 kernel: session_stat: dev=fd:5 state=6 blksize=4096 mmapsize=262144 messages.1:561:May 4... (2 Replies)
Discussion started by: Anjan Ganguly
2 Replies

2. Shell Programming and Scripting

Transfer the logs being thrown into /var/log/messages into another file example /var/log/volumelog

I have been searching and reading about syslog. I would like to know how to Transfer the logs being thrown into /var/log/messages into another file example /var/log/volumelog. tail -f /var/log/messages dblogger: msg_to_dbrow: no logtype using missing dblogger: msg_to_dbrow_str: val ==... (2 Replies)
Discussion started by: kenshinhimura
2 Replies

3. Shell Programming and Scripting

Log all the commands input by user at real time in /var/log/messages

Below is my script to log all the command input by any user to /var/log/messages. But I cant achieve the desired output that i want. PLease see below. function log2syslog { declare COMMAND COMMAND=$(fc -ln -0) logger -p local1.notice -t bash -i -- "$USER:$COMMAND" } trap... (12 Replies)
Discussion started by: invinzin21
12 Replies

4. SuSE

Some error messages in var/log/messages

How are you? SUSE V10 and 11. In /var/log/messages I see these lines in some servers. I'd like to know what causes these errors and how to fix them. Thank you, error: PAM: Authentication failure for root from XXXXXXXX Did not receive identification string from XXXXXXX Invalid user suse-gm... (2 Replies)
Discussion started by: JDBA
2 Replies

5. UNIX for Dummies Questions & Answers

fprintd messages in /var/log/messages

Whenever a user uses su I get the following error messages in /var/log/messages: Nov 23 04:24:55 <REMOVED> abrt: saved core dump of pid 26141 (/usr/libexec/fprintd) to /var/spool/abrt/ccpp-1322018695-26141.new/coredump (753664 bytes) Nov 23 04:24:55 <REMOVED> abrtd: Directory... (3 Replies)
Discussion started by: JakesHat
3 Replies

6. Shell Programming and Scripting

How can view log messages between two time frame from /var/log/message or any type of log files

How can view log messages between two time frame from /var/log/message or any type of log files. when logfiles are very big and especially many messages with in few minutes, I would like to display log messages between 5 minute interval. Could you pls give me the command? (1 Reply)
Discussion started by: johnveslin
1 Replies

7. Solaris

Difference between /var/log/syslog and /var/adm/messages

Hi, Is the contents in /var/log/syslog and /var/adm/messages are same?? Regards (3 Replies)
Discussion started by: vks47
3 Replies

8. UNIX for Advanced & Expert Users

/var/adm/messages vs /var/log/messages

The /var/adm/messages in Solaris seem to log more system messages/errors compared to /var/log/messages in Linux. I checked the log level in Linux and they seem OK. Is there any other log file that contains the messages or is it just that Linux doesn't log great many things? (2 Replies)
Discussion started by: gomes1333
2 Replies

9. Solaris

diff b/w /var/log/syslog and /var/adm/messages

hi sirs can u tell the difference between /var/log/syslogs and /var/adm/messages in my working place i am having two servers. in one servers messages file is empty and syslog file is going on increasing.. and in another servers message file is going on increasing but syslog file is... (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

10. UNIX for Dummies Questions & Answers

/var/log/messages

Which programm, deamon or script is responsible for filling the file /var/log/messages ? (1 Reply)
Discussion started by: Cozmic
1 Replies
Login or Register to Ask a Question