Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Sys::Syslog no output

by sunadmn (Curate)
on Jan 23, 2006 at 17:03 UTC ( [id://524971]=perlquestion: print w/replies, xml ) Need Help??

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

For some reason I am not getting anything to syslog and I am lost to where I went wrong. Anyone have any ideas on this one??
#!/usr/bin/perl use strict; use Sys::Syslog; my $dir = "/usr/local/chaser/"; my $file = "load_data_file.*"; my $ls = '/bin/ls'; my $wc = "/bin/wc -l"; my $cmd = "$ls $dir" . "$file \|" . "$wc"; open(RET, "$cmd |"); chomp(my @return = <RET>); close(RET); if(@return >1) { openlog("files", "user", "system"); syslog('alert', '%s', 'this is a test'); closelog(); }
SUNADMN
USE PERL

Replies are listed 'Best First'.
Re: Sys::Syslog no output
by McDarren (Abbot) on Jan 23, 2006 at 17:55 UTC
    The line:
    if (@return > 1)
    is evaluating @return in scalar context. And because your $cmd returns just a single line, you are effectively saying:
    if (1 >1)
    of course, 1 will never be greater than 1, so you get no output :p
    Change it to:
    if (@return) {

    Cheers,
    Darren :)

      Ahhh thank you a million times over that did the trick.
      SUNADMN
      USE PERL
Re: Sys::Syslog no output
by ides (Deacon) on Jan 23, 2006 at 17:27 UTC

    I believe your openlog() is wrong. It should be:

    openlog('files', 'pid', 'user');

    I think that's what you're looking for.

    Frank Wiles <frank@revsys.com>
    www.revsys.com

      Hmm I did try that and still for some reason nothing.
      SUNADMN
      USE PERL
Re: Sys::Syslog no output
by radiantmatrix (Parson) on Jan 23, 2006 at 17:55 UTC
Re: Sys::Syslog no output
by idsfa (Vicar) on Jan 23, 2006 at 17:54 UTC

    Does your OS support a logging facility called system (not to be confused with syslog)? If so, is it being logged where you think it is being logged (check /etc/syslog.conf)?


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://524971]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-03-19 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found