get messages from background task to log file (start-stop-daemon with perl script stderr)

G

Grischa Schuering

Hello,

I have a perl daemon running using the start-stop-daemon in background mode.
Now I would like to get the mnessages, that were originally send on STDIN,
STDOUT, STDERR to a file.

Using start-stop-daemon --exec $DAEMON --background >$2 file.log is not
working. No wonder, sonce a backround task should not send any information
to STDIN and so on.

What is the correct command to get the mesages to file or syslog
(whatever)???
 
D

David Efflandt

Hello,

I have a perl daemon running using the start-stop-daemon in background mode.
Now I would like to get the mnessages, that were originally send on STDIN,
STDOUT, STDERR to a file.

Using start-stop-daemon --exec $DAEMON --background >$2 file.log is not
working. No wonder, sonce a backround task should not send any information
to STDIN and so on.

What is the correct command to get the mesages to file or syslog
(whatever)???

Look for SyS::Syslog module.

Working example:

#!/usr/bin/perl -w
# Name of this script
if ($0 =~ m|/([^/]+)$|) { $id = $1; } else { $id = $0; }
use Sys::Syslog qw:)DEFAULT setlogsock);
setlogsock 'unix' || die "Can't setlogsock";
sub mylog {
my $msg = shift;
chomp $msg; # if needed
syslog('info',"$id\[$$]:$msg"); closelog();
}
mylog("I'm running");


The script was called 'logme', result in syslog:

Sep 29 18:48:27 efflandt logme[31707]: I'm running
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top