Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Sys::Syslog no output

by sunadmn (Curate)
on Jan 23, 2006 at 17:03 UTC ( #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

Comment on Sys::Syslog no output
Download Code
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 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
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 radiantmatrix (Parson) on Jan 23, 2006 at 17:55 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-09-20 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (153 votes), past polls