Operating System - HP-UX
1843979 Members
1723 Online
110226 Solutions
New Discussion

Re: Script okay when changing run levels but not boot up!

 
SOLVED
Go to solution

Script okay when changing run levels but not boot up!

Hello,

I have a script which I would like to start automatically when my system boots. I've created a stop/start script (placed in /sbin/init.d) and added the appropriate S* and K* files (in /sbin/rc2.d and rc3.d) which link to it. To start my script it uses the command: /myscriptname >/dev/null 2>errorfile &

My problem is that when I change run levels ie. 3->1->3 or 3->2->3 the script is started and stopped fine, however when I re-boot the system my script is started okay, but then stops soon after (I can tell this by files that are created). Is there something different about the enviroment perhaps or the way the init process works at boot-up?

Any other ideas?

Thanks in advance
13 REPLIES 13
Mark van Hassel
Respected Contributor

Re: Script okay when changing run levels but not boot up!

Hi,

Check $PATH at boot time (which is minimal). For debugging add set -x to your script and then check the error logfile.

HtH,

Mark
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
Mark van Hassel
Respected Contributor

Re: Script okay when changing run levels but not boot up!

What is in the /etc/rc.log ?
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us

Re: Script okay when changing run levels but not boot up!

Hello Mark,

I've checked /etc/rc.log and that just shows that the script started okay which makes sense as I know it starts, it just then stops a little later.

I'm just going to re-boot now with set -x on to check the output from both scripts. Sorry for being dim, but how do I check the $PATH at boot time? Also could this be related to the terminal which starts the script? (just a guess as I'm a novice!)

Thanks
Mark van Hassel
Respected Contributor

Re: Script okay when changing run levels but not boot up!

You can check with "echo $PATH" in your script. But when a command is not found it would show an error in your error log file.

Are there any terminal related commands in your script ?
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us

Re: Script okay when changing run levels but not boot up!

Hello Mark,

Yes I agree, I should see some output in /etc/rc.log if the problem was path related.

Looking in rc.log after setting set -x, the following was produced exactly the same for changing run-levels and re-boot:

Start filtering script for MC trace_text (filter_tt)
Output from "/sbin/rc3.d/S050filter_trace_text start":
----------------------------
+ echo filter_tt started
+ /usr/contrib/scripts/filter_tt/filter_tt
filter_tt started
+ exit 0
+ 1> /tmp/filtout

This all looks okay to me.

Regarding 'terminal type' commands in my main script, I have several echo's, but these are all redirected to a file so avoid stdout. Checking the output of my main script after setting set -x on, I found that it stop working on a sleep command. Is sleep perhaps the problem?

Thank
Mark van Hassel
Respected Contributor

Re: Script okay when changing run levels but not boot up!

Hi Stephen,

It all looks fine.
Sleep will halt processing for the amount of time specified and should continue afterwards.

Since you start your script (filter_tt) in the background you should use exit 4 i.s.o. 0 :
The return values for startup scripts are as follows:

0 Script exited without error.
1 Script encountered errors.
2 Script was skipped due to overriding control variables from
/etc/rc.config.d files, or for other reasons, and did not
actually do anything.
4 Script exited without error and started a process in
background mode.

See man rc.

What's in /tmp/filtout and errorfile ?

The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us

Re: Script okay when changing run levels but not boot up!

Hello Mark,

/tmp/filtout is empty, and errorfile just contains the debugged commands ending in + sleep 60.

I just tried setting exit 4 and this is the output:

+ echo filter_tt started
filter_tt started
+ rval=4
+ exit 4
+ /usr/contrib/scripts/filter_tt/filter_tt
"/sbin/rc3.d/S050filter_trace_text start" FAILED
+ 1> /tmp/filtout

Does that make sense? I checked the errorfile and /tmp/filtout and these had no clues. If I change run-levels up and down the output changes slightly to:

+ echo filter_tt started
filter_tt started
+ rval=4
+ exit 4
+ /usr/contrib/scripts/filter_tt/filter_tt
"/sbin/rc3.d/S050filter_trace_text start" FAILED
+ 1> /tmp/filtout

In both cases the outcomes are the same, i.e changing run-level works, re-boot doesn't!

thank
Mark van Hassel
Respected Contributor

Re: Script okay when changing run levels but not boot up!

Hi Stephen,

Are you on 10.20 ? Since that release does not have the "exit 4" option.

What comes after the sleep 60 command ?
Is /usr/contrib/scripts/filter_tt/filter_tt still running ? (check with ps)
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
Solution

Re: Script okay when changing run levels but not boot up!

Hi,

What happens if you try using nohup?

nohup /myscriptname >/dev/null 2>errorfile &

HTH

Duncan

I am an HPE Employee
Accept or Kudo

Re: Script okay when changing run levels but not boot up!

Hello Mark,

I'm on 11i and the man page for rc checks out fine saying I can use exit 4. Very peculiar.

The next line after the sleep 60 is back at the top of a while loop:

new_num_lines=`wc -l $file_name | cut -f 1 -d " " `

Nothing strange there I don't think either. filter_tt is still running if I have just changed run-levels but not on reboot.

thanks

Hello Duncan,

I tried nohup originally and then was advised that putting in the background was better. How can I direct the nohup.out to a specific location?

thanks
Mark van Hassel
Respected Contributor

Re: Script okay when changing run levels but not boot up!

Stephen,

I still think it has something to do with the process parent-child relation. What is the parent process of filter_tt when changing run levels ?
When you redirect the output when using nohup no nohup.out file will be created.
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us

Re: Script okay when changing run levels but not boot up!

Stephen,

From the nohup man page:

nohup executes command with hangups and quits ignored. If output is
not redirected by the user, both standard output and standard error
are sent to nohup.out.

As it looks like you are already re-directing your stdout & stderr elsewhere, don't worry about nohup.out.

HTH

Duncan

I am an HPE Employee
Accept or Kudo

Re: Script okay when changing run levels but not boot up!

Hello Mark,

Yes I agree this definetly looks like a parent-child problem. I'm pretty new to HP-UX but I've come across similar problems on other systems so I'm sure this is tied in somehow.

I have tried using nohup and this works okay in changing run-levels and re-booting which is good so I'll have to go with this method for now.

When I change run levels the parent process pid is 1 (with and without nohup) which is what you'd expect I guess.

Thanks