Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to convert some #!/bin/sh scripts into #!/usr/bin/perl scripts, and I'm not having any luck.

I've tried following the examples in "perldoc Sys::Syslog", but for some reason they're not working. My example script (below) produces no output either to the terminal I run it in, or to /var/log/messages (which I'm watching via a 'tail -f').

OS is RH Linux 7.0, Perl is 5.6.0. Sys::Syslog version is 0.1, I think.

Sample script:

#!/usr/bin/perl -w $|++; use strict; use Sys::Syslog; # For openlog() call my $ident = 'somefunprocessname'; my $logopt = 'pid'; my $facility = 'user'; # For syslog() call my $priority = 'notice'; my $mask = ''; my $format = ''; my @args = '-ip user.notice -t somefunprocessname'; openlog($ident, $logopt, $facility); syslog($priority, 'asdfasdf'); closelog();

Any and all help is appreciated. TIA mucho...

-YendorMike

Replies are listed 'Best First'.
Re: Sys::Syslog produces no output...
by danger (Priest) on Dec 18, 2001 at 11:38 UTC

    Your syslogd is perhaps using 'udp' by default, try the setlogsock() function (see docs):

    use Sys::Syslog qw/:DEFAULT setlogsock/; setlogsock('unix'); openlog($0, 'pid', 'user'); syslog('notice', 'blah blah: %d', time()); closelog();

    There is also the Unix::Syslog module with an interface more like the unix syslog call:

    use Unix::Syslog qw/:subs :macros/; openlog($0, LOG_PID, LOG_USER); syslog(LOG_NOTICE, 'blah blah: %d', time()); closelog();
Re: Sys::Syslog produces no output...
by fokat (Deacon) on Dec 18, 2001 at 18:38 UTC
    In order to use Sys::Syslog, you must ensure two things:

    • Your syslogd (the one that actually writes the log files), is set up to accept messages through an UDP socket. In Linux systems, you must insure that syslogd is running with the -r flag set.

    • Your /etc/syslog.conf must contain configuration information that sends the logs of your script to a suitable destination. man syslog.conf is your friend here.

      I'm probably too paranoid, but I frequently use config files that look like

      *.* /dev/console *.* /var/log/my-huge-large-log-file
      Remember that whatever files you choose to send the output, must already exist for syslogd to write to them. Normally, you will change the config file, issue a

      bash# touch /var/log/my-huge-log-file bash# /etc/rc.d/init.d/syslog restart
    Best of luck.

Re: Sys::Syslog produces no output...
by fuzzysteve (Beadle) on Dec 18, 2001 at 18:07 UTC
    As far as I remember, sys::syslog needs syslogd to accept remote connections to be able to log to it.
    Unix::Syslog doesn't (which is why i use it).
porting sh scripts to perl
by boo_radley (Parson) on Dec 18, 2001 at 20:09 UTC
    I wonder if merlyn still endorses, or if you would find useful sh2perl?
    Interesting that I read this question right after plowing through The perl timeline, which mentioned this work of merlyn's.