syslog function try to write to /dev folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnhelen
    New Member
    • Sep 2007
    • 8

    syslog function try to write to /dev folder

    hello

    In a perl script for a cronjob, there is a function:

    Code:
    sub _write_sys_log {
    my $seft = shift;
    my $level = shift;
    my $string = shift;
    syslog($level, '%s', "$string");
    }
    This function is called from other function. I think that the function above should write logs to syslog file. However, it tries to write logs to /dev/consolog. As /dev/consolog is own by root, so it cannot write logs to this file. Therefore, it throws an error.

    My question is how I can write these logs to syslog file. I am not good in perl and I am not the person who wrote this script, so please have some suggestions

    Many thanks
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by johnhelen
    hello

    In a perl script for a cronjob, there is a function:

    Code:
    sub _write_sys_log {
    my $seft = shift;
    my $level = shift;
    my $string = shift;
    syslog($level, '%s', "$string");
    }
    This function is called from other function. I think that the function above should write logs to syslog file. However, it tries to write logs to /dev/consolog. As /dev/consolog is own by root, so it cannot write logs to this file. Therefore, it throws an error.

    My question is how I can write these logs to syslog file. I am not good in perl and I am not the person who wrote this script, so please have some suggestions

    Many thanks
    I am going to take a guess here and say that in the script you are looking at, that they are using the Sys::Syslog module from CPAN. I say that because that is where I see the syslog() function defined.

    That said, you should read that link as they probably have the open() function defined and pointing to the file it is trying to write to.

    Also, I am guessing that you mean that this script is "run by the crontab". In that case, the reason they have this pointing to a root permission log is because when crontab jobs get run, it is the root user that is doing the executing.

    Regards,

    Jeff

    Comment

    • johnhelen
      New Member
      • Sep 2007
      • 8

      #3
      Thank you, you right

      I check and there is openlog call as:

      openlog('NEW', '', 'local2);

      Is it correct

      Thanks

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Originally posted by johnhelen
        Thank you, you right

        I check and there is openlog call as:

        openlog('NEW', '', 'local2);

        Is it correct

        Thanks
        You may want to read the functions part of the documentation. The first function is openlog() which it says has 3 parameters, where yours only has 2.

        Unfortunately I haven't used this module and am unfamiliar with any caveats it may have, but it does look like that needs to be fixed.

        Regards,

        Jeff

        Comment

        • johnhelen
          New Member
          • Sep 2007
          • 8

          #5
          Thanks for very quick reply
          I also I discover that the "local2" facility (inside openlog function) is not in the /etc/syslog.conf file. Do you think that is the problem too ???


          ---------------------------------
          Originally posted by numberwhun
          You may want to read the functions part of the documentation. The first function is openlog() which it says has 3 parameters, where yours only has 2.

          Unfortunately I haven't used this module and am unfamiliar with any caveats it may have, but it does look like that needs to be fixed.

          Regards,

          Jeff

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            Originally posted by johnhelen
            Thanks for very quick reply
            I also I discover that the "local2" facility (inside openlog function) is not in the /etc/syslog.conf file. Do you think that is the problem too ???


            ---------------------------------
            I would say that is the problem. I would track it down and see if the facility is modifiable.

            Comment

            • johnhelen
              New Member
              • Sep 2007
              • 8

              #7
              "I would track it down and see if the facility is modifiable"

              You mean that I should add one entry into the syslog.conf

              local2.* /var/logs/syslog

              So the log message will be written into syslog file ?

              Many thanks for great help

              Comment

              • numberwhun
                Recognized Expert Moderator Specialist
                • May 2007
                • 3467

                #8
                Originally posted by johnhelen
                "I would track it down and see if the facility is modifiable"

                You mean that I should add one entry into the syslog.conf

                local2.* /var/logs/syslog

                So the log message will be written into syslog file ?

                Many thanks for great help
                Yes, that's exactly what I mean. Hope it works for you!

                Regards,

                Jeff

                Comment

                Working...