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

D

deanjones7

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?
 
P

Peter Makholm

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
 
U

usenet

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.
 
A

Anno Siegel

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
 
D

deanjones7

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.
 
D

deanjones7

Anno said:
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?
 
M

Mark Clements

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
 
A

Anno Siegel

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.


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
 
A

Anno Siegel

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
 
A

Anno Siegel

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?
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.
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
 
D

deanjones7

Mark said:
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.
 
D

deanjones7

Anno said:
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.
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 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 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.
 
D

deanjones7

Anno said:
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.
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.
 
A

Anno Siegel

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".

[...]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top