What is required for perl scripts to run correct when launched from rc scripts on HPUX 11?

Discussion in 'Perl Misc' started by deanjones7@gmail.com, Sep 6, 2007.

  1. Guest

    I have a perl script that's part of a pipe (i.e. program | perl
    script). The perl script reads the stdout of the program on the other
    end of the pipe and logs/emails any error messages.

    This works OK if run from the command line. However, the perl script
    fails without any errors when the system is booted. There's nothing
    useful in /etc/rc.log (just some "not a typewriter" messages since the
    shell script that starts the above does an su first).

    I suspect its a file handle issue but I don't know enough about perl
    to figure out what.

    Can anyone help?
    , Sep 6, 2007
    #1
    1. Advertising

  2. writes:

    > This works OK if run from the command line. However, the perl script
    > fails without any errors when the system is booted. There's nothing
    > useful in /etc/rc.log (just some "not a typewriter" messages since the
    > shell script that starts the above does an su first).


    And you have made sure that perl is actually run. The $PATH might not
    be set to the same set og directories as when you are logged in. Try
    use the full path to perl in you script.

    # This is not a perl answer

    //Makholm
    Peter Makholm, Sep 6, 2007
    #2
    1. Advertising

  3. Guest

    On Sep 6, 1:06 am, wrote:
    > the perl script fails without any errors when the system is booted.


    That means NOTHING. How do you know it fails? How do you even know
    it runs? Why would you think it should run on a reboot?

    With no code and a meaningless description of the problem I doubt
    anyone is psychic enough to advise you of what your actual problem is.


    --
    The best way to get a good answer is to ask a good question.
    David Filmer (http://DavidFilmer.com)
    , Sep 6, 2007
    #3
  4. Anno Siegel Guest

    On 2007-09-06 10:17:09 +0200, said:

    > On Sep 6, 1:06 am, wrote:
    >> the perl script fails without any errors when the system is booted.

    >
    > That means NOTHING. How do you know it fails? How do you even know
    > it runs? Why would you think it should run on a reboot?


    Well, the subject mentions "... launched from rc scripts" which I take
    to mean it is called from one of the /etc/*.rc scripts (or however these
    are organized in HPUX). These scripts run at boot time to set up the
    system and thus run at a time when the system is not yet completely set
    up. Lots of things can go wrong if something is called too early in the
    process.

    Anno
    Anno Siegel, Sep 6, 2007
    #4
  5. Guest

    wrote:
    > On Sep 6, 1:06 am, wrote:
    > > the perl script fails without any errors when the system is booted.

    >
    > That means NOTHING. How do you know it fails?


    Because if it was running I would see it with "ps -ef" and it would be
    reporting errors as they come through the pipe.

    > How do you even know it runs?
    > Why would you think it should run on a reboot?


    Which part of my original post didn't you comprehend?

    > With no code and a meaningless description of the problem I doubt
    > anyone is psychic enough to advise you of what your actual problem is.


    That's fine. I was hoping for some obvious finger pointing before I
    delve into more advanced diagnostics.
    , Sep 6, 2007
    #5
  6. Guest

    Anno Siegel wrote:
    > On 2007-09-06 10:17:09 +0200, said:
    >
    > > On Sep 6, 1:06 am, wrote:
    > >> the perl script fails without any errors when the system is booted.

    > >
    > > That means NOTHING. How do you know it fails? How do you even know
    > > it runs? Why would you think it should run on a reboot?

    >
    > Well, the subject mentions "... launched from rc scripts" which I take
    > to mean it is called from one of the /etc/*.rc scripts (or however these
    > are organized in HPUX).


    That's correct. There's a start/stop script in /sbin/init.d with the
    usual links to the rc? directories. That script works correctly when
    run interactively.

    > These scripts run at boot time to set up the
    > system and thus run at a time when the system is not yet completely set
    > up. Lots of things can go wrong if something is called too early in the
    > process.


    The funny thing is I have another perl script that runs fine when run
    at boot. The only difference is that its not listening on a pipe like
    the problematic one is.

    I wonder if its how I use STDIN. In the problematic script I just do -

    while (<>)
    {
    ....
    }

    to read input from the pipe. Should I be using STDIN explicitly
    instead?
    , Sep 6, 2007
    #6
  7. Re: What is required for perl scripts to run correct when launchedfrom rc scripts on HPUX 11?

    wrote:
    > Anno Siegel wrote:
    >> On 2007-09-06 10:17:09 +0200, said:
    >>
    >>> On Sep 6, 1:06 am, wrote:
    >>>> the perl script fails without any errors when the system is booted.
    >>> That means NOTHING. How do you know it fails? How do you even know
    >>> it runs? Why would you think it should run on a reboot?

    >> Well, the subject mentions "... launched from rc scripts" which I take
    >> to mean it is called from one of the /etc/*.rc scripts (or however these
    >> are organized in HPUX).

    >
    > That's correct. There's a start/stop script in /sbin/init.d with the
    > usual links to the rc? directories. That script works correctly when
    > run interactively.


    Add some logging to the script? I'd use Log::Log4perl or one of the
    syslog alternatives.

    $logger->info("starting up");
    ....

    $logger->debug("processing line number $count");

    $logger->info("exiting normally");

    ....

    and

    (assuming you've wrapped the main body of the program in eval {} )

    $logger->error("exiting abnormally with error=$@");





    Mark
    Mark Clements, Sep 6, 2007
    #7
  8. Anno Siegel Guest

    On 2007-09-06 14:05:18 +0200, said:

    > Anno Siegel wrote:
    >> On 2007-09-06 10:17:09 +0200, said:
    >>
    >>> On Sep 6, 1:06 am, wrote:
    >>>> the perl script fails without any errors when the system is booted.
    >>>
    >>> That means NOTHING. How do you know it fails? How do you even know
    >>> it runs? Why would you think it should run on a reboot?

    >>
    >> Well, the subject mentions "... launched from rc scripts" which I take
    >> to mean it is called from one of the /etc/*.rc scripts (or however these
    >> are organized in HPUX).

    >
    > That's correct. There's a start/stop script in /sbin/init.d with the
    > usual links to the rc? directories.


    It would have been a good idea to mention that explicitly in the body of
    your posting. "Launched from rc" is not part of any standard terminology.

    > That script works correctly when
    > run interactively.
    >
    >> These scripts run at boot time to set up the
    >> system and thus run at a time when the system is not yet completely set
    >> up. Lots of things can go wrong if something is called too early in the
    >> process.

    >
    > The funny thing is I have another perl script that runs fine when run
    > at boot.


    The behavior depends heavily on *when* the script is run during the
    startup process. "Run at boot" is much too unspecific.

    > The only difference is that its not listening on a pipe like
    > the problematic one is.


    The Perl scripts aren't identical, are they? I bet the pipe isn't the
    only difference. In fact, pipe behavior sounds like a rather unlikely
    candidate.

    > I wonder if its how I use STDIN. In the problematic script I just do -
    >
    > while (<>)
    > {
    > ...
    > }
    >
    > to read input from the pipe. Should I be using STDIN explicitly
    > instead?


    I have no idea. Post the code of the script, the actual call, and
    describe in what stage of startup the call happens. Is perl even
    part of the HPUX 11 distribution? Are all modules your script may
    be using?

    In fact, you might be better off asking in a HPUX-oriented newsgroup.
    The problem may not be specific to perl at all.

    Anno
    Anno Siegel, Sep 6, 2007
    #8
  9. Anno Siegel Guest

    Re: What is required for perl scripts to run correct when launched from rc scripts on HPUX 11?

    On 2007-09-06 14:13:25 +0200, Mark Clements
    <> said:

    > wrote:
    >> Anno Siegel wrote:
    >>> On 2007-09-06 10:17:09 +0200, said:
    >>>
    >>>> On Sep 6, 1:06 am, wrote:
    >>>>> the perl script fails without any errors when the system is booted.
    >>>> That means NOTHING. How do you know it fails? How do you even know
    >>>> it runs? Why would you think it should run on a reboot?
    >>> Well, the subject mentions "... launched from rc scripts" which I take
    >>> to mean it is called from one of the /etc/*.rc scripts (or however these
    >>> are organized in HPUX).

    >>
    >> That's correct. There's a start/stop script in /sbin/init.d with the
    >> usual links to the rc? directories. That script works correctly when
    >> run interactively.

    >
    > Add some logging to the script? I'd use Log::Log4perl or one of the
    > syslog alternatives.


    Logging is a good idea, but syslog assumes that syslogd is already running
    when the script starts. During startup there is no guarantee for that.

    To be sure, create a logfile in the / file system (the only one that can
    be relied on to be mounted), and print() log messages to that file directly.

    Anno
    Anno Siegel, Sep 6, 2007
    #9
  10. Anno Siegel Guest

    On 2007-09-06 13:59:58 +0200, said:

    > wrote:
    >> On Sep 6, 1:06 am, wrote:
    >>> the perl script fails without any errors when the system is booted.

    >>
    >> That means NOTHING. How do you know it fails?

    >
    > Because if it was running I would see it with "ps -ef"


    Would you? How long does that thing run? Do you even have
    an interactive process to run ps from when the script is
    supposed to be starting?

    > and it would be
    > reporting errors as they come through the pipe.


    Reporting to where? And what errors? Last thing you were in doubt
    if the pipe even works. How can you rely on it to show if the script
    is started?

    >> How do you even know it runs?
    >> Why would you think it should run on a reboot?

    >
    > Which part of my original post didn't you comprehend?


    Probably the obscure "launched from rc" part you hid in an
    overlong subject line. Essential information belongs in the
    body of a posting. This is a Perl group, not a Unix goup.
    Some posters may never have seen an rc* file in their lives.

    >> With no code and a meaningless description of the problem I doubt
    >> anyone is psychic enough to advise you of what your actual problem is.

    >
    > That's fine. I was hoping for some obvious finger pointing before I
    > delve into more advanced diagnostics.


    Then you were posting to the wrong newsgroup. The situation during
    startup is system-specific, not language-specific.

    Anno
    Anno Siegel, Sep 6, 2007
    #10
  11. Guest

    Mark Clements wrote:
    > wrote:
    > > Anno Siegel wrote:
    > >> On 2007-09-06 10:17:09 +0200, said:
    > >>
    > >>> On Sep 6, 1:06 am, wrote:
    > >>>> the perl script fails without any errors when the system is booted.
    > >>> That means NOTHING. How do you know it fails? How do you even know
    > >>> it runs? Why would you think it should run on a reboot?
    > >> Well, the subject mentions "... launched from rc scripts" which I take
    > >> to mean it is called from one of the /etc/*.rc scripts (or however these
    > >> are organized in HPUX).

    > >
    > > That's correct. There's a start/stop script in /sbin/init.d with the
    > > usual links to the rc? directories. That script works correctly when
    > > run interactively.

    >
    > Add some logging to the script? I'd use Log::Log4perl or one of the
    > syslog alternatives.
    >
    > $logger->info("starting up");
    > ...
    >
    > $logger->debug("processing line number $count");
    >
    > $logger->info("exiting normally");
    >
    > ...
    >
    > and
    >
    > (assuming you've wrapped the main body of the program in eval {} )
    >
    > $logger->error("exiting abnormally with error=$@");


    I just tried a "set -x" in the shell script that acts as a wrapper to
    the real stuff then ran that from cron.

    For some strange reason, cron assigns a pty to the process! So I get
    gore like this -

    ttytype: couldn't open /dev/tty for reading
    stty: : Not a typewriter
    Not a terminal
    logout

    At the start even though I do -

    if tty -s; then
    ....
    fi

    in the .profile of the account this runs under. Ver odd.

    Anyway, the rest of the "set -x" output doesn't show anything amiss -
    although it appears that POSIX shells start the program on the
    receiving end of a pipe before the program on the front of a pipe. Not
    really relevant here, just something I didn't know before.
    , Sep 10, 2007
    #11
  12. Guest

    Anno Siegel wrote:
    > On 2007-09-06 14:05:18 +0200, said:
    >
    > > Anno Siegel wrote:
    > >> On 2007-09-06 10:17:09 +0200, said:
    > >>
    > >>> On Sep 6, 1:06 am, wrote:
    > >>>> the perl script fails without any errors when the system is booted.
    > >>>
    > >>> That means NOTHING. How do you know it fails? How do you even know
    > >>> it runs? Why would you think it should run on a reboot?
    > >>
    > >> Well, the subject mentions "... launched from rc scripts" which I take
    > >> to mean it is called from one of the /etc/*.rc scripts (or however these
    > >> are organized in HPUX).

    > >
    > > That's correct. There's a start/stop script in /sbin/init.d with the
    > > usual links to the rc? directories.

    >
    > It would have been a good idea to mention that explicitly in the body of
    > your posting. "Launched from rc" is not part of any standard terminology.


    I would have expected any experience Unix person to know what an rc
    script is and the related terminology, but no matter.

    > > That script works correctly when
    > > run interactively.
    > >
    > >> These scripts run at boot time to set up the
    > >> system and thus run at a time when the system is not yet completely set
    > >> up. Lots of things can go wrong if something is called too early in the
    > >> process.

    > >
    > > The funny thing is I have another perl script that runs fine when run
    > > at boot.

    >
    > The behavior depends heavily on *when* the script is run during the
    > startup process. "Run at boot" is much too unspecific.


    OK, run level 3. About one of the last scripts to run.

    > > The only difference is that its not listening on a pipe like
    > > the problematic one is.

    >
    > The Perl scripts aren't identical, are they?


    Its the same script. The only difference I can see is the fact that
    there's no pseudo-tty attached to the processes run from init.d.

    > I bet the pipe isn't the only difference. In fact, pipe behavior sounds like a rather unlikely
    > candidate.


    Yes, I don't think it is. There was one point where I had an explicit
    exit in the perl script after it read in a config file (I was printing
    the config options back out to ensure it was doing it correctly). The
    exit caused the other program on the front of the pipe to die. I then
    spent some time trying to work out if it was a SIGPIPE problem (by
    sending kill -PIPE signals to that program) to no effect. So the exit
    in the perl script must send a different signal back (although I'm not
    sure why. I would expect SIGPIPE but HP-UX has some oddities).

    > > I wonder if its how I use STDIN. In the problematic script I just do -
    > >
    > > while (<>)
    > > {
    > > ...
    > > }
    > >
    > > to read input from the pipe. Should I be using STDIN explicitly
    > > instead?

    >
    > I have no idea. Post the code of the script, the actual call, and
    > describe in what stage of startup the call happens.


    Its a bit difficult due to commercial obligations (contracts, etc. I'm
    sure you're aware of the issues).

    Anyway, if you must know, I took an existing perl script found here -
    http://www.peppler.org/downloads/scripts (Its the one called
    log_watcher.pl.)
    and modified it to read from stdin (i.e. a pipe) rather than from a
    file location. I also optimised the regexps and cleaned up some of the
    logic. It all works fine (at least when I start the scripts
    interactively).

    > Is perl even part of the HPUX 11 distribution?


    I have no idea. 'perl -v' reports -

    This is perl, v5.8.0 built for PA-RISC1.1-thread-multi
    (with 1 registered patch, see perl -V for more detail)

    > Are all modules your script may be using?


    I'm not sure what you mean.

    > In fact, you might be better off asking in a HPUX-oriented newsgroup.
    > The problem may not be specific to perl at all.


    I can't find a specific HP-UX group under comp.unix.*. I might try a
    generic one later if I still can't solve this.
    , Sep 10, 2007
    #12
  13. Guest

    Anno Siegel wrote:
    > On 2007-09-06 13:59:58 +0200, said:
    >
    > > wrote:
    > >> On Sep 6, 1:06 am, wrote:
    > >>> the perl script fails without any errors when the system is booted.
    > >>
    > >> That means NOTHING. How do you know it fails?

    > >
    > > Because if it was running I would see it with "ps -ef"

    >
    > Would you?


    Yes. If its not showing up under a ps listing but the program on the
    front of the pipe is, I think you can safely surmise that the perl
    script has died.

    > How long does that thing run?


    Its a log monitor. It should run as long as the program on the front
    of the pipe runs.

    > Do you even have
    > an interactive process to run ps from when the script is
    > supposed to be starting?


    I'm not sure what your asking. I can run top, glance or ps. Its a bit
    hard to do that when the system is booting, of course.

    > > and it would be
    > > reporting errors as they come through the pipe.

    >
    > Reporting to where?


    Email for now. See the original. It also pages but I still have to
    modify that part for local use.

    > And what errors?


    Errors that the program on the front of the pipe might report.

    > Last thing you were in doubt if the pipe even works.


    I was? The pipe works fine. Its the manner of starting the main script
    (boot time or interactively) that seems to be the problem. The only
    difference there is that there's no pty attached to the processes. I
    can't identify anything as being an issue. For now, anyway.

    > How can you rely on it to show if the script is started?


    I'm not sure what you mean. The pipe is just part of the process in
    the calling shell script.
    , Sep 10, 2007
    #13
  14. Anno Siegel Guest

    On 2007-09-10 05:10:45 +0200, said:

    > Anno Siegel wrote:
    >> On 2007-09-06 14:05:18 +0200, said:
    >>
    >>> Anno Siegel wrote:
    >>>> On 2007-09-06 10:17:09 +0200, said:
    >>>>
    >>>>> On Sep 6, 1:06 am, wrote:
    >>>>>> the perl script fails without any errors when the system is booted.
    >>>>>
    >>>>> That means NOTHING. How do you know it fails? How do you even know
    >>>>> it runs? Why would you think it should run on a reboot?
    >>>>
    >>>> Well, the subject mentions "... launched from rc scripts" which I take
    >>>> to mean it is called from one of the /etc/*.rc scripts (or however these
    >>>> are organized in HPUX).
    >>>
    >>> That's correct. There's a start/stop script in /sbin/init.d with the
    >>> usual links to the rc? directories.

    >>
    >> It would have been a good idea to mention that explicitly in the body of
    >> your posting. "Launched from rc" is not part of any standard terminology.

    >
    > I would have expected any experience Unix person to know what an rc
    > script is and the related terminology, but no matter.


    Perl is not restricted to the Unix world. A Perl expert is no automatically
    an "experienced Unix person".

    [...]

    >>> to read input from the pipe. Should I be using STDIN explicitly
    >>> instead?

    >>
    >> I have no idea. Post the code of the script, the actual call, and
    >> describe in what stage of startup the call happens.

    >
    > Its a bit difficult due to commercial obligations (contracts, etc. I'm
    > sure you're aware of the issues).


    You're on your own then. We can't debug code we can't see.

    > Anyway, if you must know, I took an existing perl script found here -
    > http://www.peppler.org/downloads/scripts (Its the one called
    > log_watcher.pl.)


    Yes, we "must know" the code you are trying to run to diagnose it.

    [...]

    Anno
    Anno Siegel, Sep 10, 2007
    #14
    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. Replies:
    0
    Views:
    188
  2. Fa Sidd
    Replies:
    12
    Views:
    204
    ara howard
    Jan 26, 2008
  3. Alex F.
    Replies:
    2
    Views:
    121
    H. Merijn Brand
    Feb 23, 2004
  4. dayo
    Replies:
    11
    Views:
    328
    Ilya Zakharevich
    Dec 16, 2005
  5. Replies:
    5
    Views:
    146
    RedGrittyBrick
    Sep 29, 2008
Loading...

Share This Page