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

Discussion in 'Perl Misc' started by Grischa Schuering, Sep 29, 2003.

  1. 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)???
     
    Grischa Schuering, Sep 29, 2003
    #1
    1. Advertising

  2. On Mon, 29 Sep 2003 23:51:22 +0200, Grischa Schuering <> wrote:
    > 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

    --
    David Efflandt - All spam ignored http://www.de-srv.com/
    http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
    http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
     
    David Efflandt, Sep 30, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. calvin01
    Replies:
    5
    Views:
    16,454
  2. Mike
    Replies:
    1
    Views:
    1,969
    GArlington
    May 12, 2008
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    473
    Jean-Paul Calderone
    Mar 20, 2009
  4. Thomas Uehlinger
    Replies:
    0
    Views:
    164
    Thomas Uehlinger
    Feb 8, 2005
  5. Justin C
    Replies:
    2
    Views:
    141
    Justin C
    Nov 22, 2013
Loading...

Share This Page