cancel
Showing results for 
Search instead for 
Did you mean: 

script problem

SOLVED
Go to solution
Domenico_5
Respected Contributor

script problem

Hi guys!!!!

I have made a script to run a software at boot.

I have linked it in /sbin/rc3.d, I have created the config file in /etc/rc.config.d

But ......
if I try to run it in a shell, it work.

If i try to run it in crontab, it work

If I reboot the server, start and ( I can see it with a ps -ef in a loop) and stop without an error or log.

Someone know why???
28 REPLIES
harry d brown jr
Honored Contributor

Re: script problem

Domenico,


It's probably an environment issue. ALL commands in scripts should have the FULL path. Never assume that the system has a PATH variable set correctly, ie:

instead of

lsof | grep TCP

should be

/usr/local/bin/lsof | grep TCP

or better yet

/usr/local/bin/lsof | /usr/bin/grep TCP

How about posting the script?

live free or die
harry
Live Free or Die
Domenico_5
Respected Contributor

Re: script problem

hi harry

No it isn't a PATH problem.

If I try to run it in a crontab, it work.

And I have write all PATH in all command
Steve Steel
Honored Contributor

Re: script problem

Hi


Put set -x in the second line

When you run it all commands are sent to standard out as they are executed

Then you can see what it is doing.


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
John Strang
Regular Advisor

Re: script problem

Hi,

Does it show that it started correctly in the /etc/rc.log file?

John

If you never make a mistake you'll never make anything.
Mark Greene_1
Honored Contributor

Re: script problem

if it's short enough, post the script.
if it's too big for that, add a -x to the first line (either #!/bin/ksh -x or #!/bin/sh -x depending on which shell you are using) and then add this line to route standard error to a log file:

exec 2>/tmp/errorlog.txt

and then boot your box and see what you get in the error log file. You should be able to tell which line the script is stopping on and what the error is.

HTH
mark
the future will be a lot like now, only later
S.K. Chan
Honored Contributor

Re: script problem

It's best to use the startup script template in /sbin/init.d/template and craft your coding in it. That usually works for me. Checking /etc/rc.log is a good idea like what John has suggested.
Mladen Despic
Honored Contributor

Re: script problem

Your script should be in /sbin/init.d and the name of the symbolic link in /sbin/rc3.d must start with Sxxx where 'xxx' is the number that determines the order of execution at the current run level.

If you want the script to execute during system shutdown, there should be another link in /sbin/rc2.d whose name starts with Kyyy,
where xxx + yyy = 1000
(this determines the opposite order of execution during system shutdown.).

During system startup the system will execute:


1)


2)


During system shutdown, the system will execute

3)


4)


Therefore your script should be able to handle the parameters:

start_msg
start
stop_msg
stop

HTH,

Mladen

Domenico_5
Respected Contributor

Re: script problem

Hi

All work correctly, with -x, with path, with all

but at boot time no!! Sigh Sigh

Whyyyyyy!!!!!!
Domenico_5
Respected Contributor

Re: script problem

mladen

I have used the template

I had check with

/sbin/rc3.d/S101nrpe start
ok
/sbin/rc3.d/S101nrpe stop
ok
/sbin/rc3.d/S101nrpe start_msg
ok
/sbin/rc3.d/S101nrpe stop_msg
ok

but at the boot time no it doesn't work!!!!!
H.Merijn Brand (procura
Honored Contributor

Re: script problem

Might it be that the script uses something from a disk that is not *YET* mounted at boot time?
Enjoy, Have FUN! H.Merijn
James R. Ferguson
Acclaimed Contributor

Re: script problem

Hi:

OK, so are you relying on something else that has *not* yet started when your script is launched??? That is, you have linked it into the startup sequence too early???

Regards!

...JRF...
John Strang
Regular Advisor

Re: script problem

Hi Domenico,
Don't be offended by this, but have you checked permissions in /sbin/rc3.d and in /sbin/init.d

And is the script in /sbin/rc3.d correctly named and linked to the script in /sbin/init.d

John
If you never make a mistake you'll never make anything.
Mark Greene_1
Honored Contributor

Re: script problem

>>All work correctly, with -x, with path, with all

but at boot time no!! Sigh Sigh <<

When you rebooted the system, what did the error log show? If it was empty, or if the timestamp on the file did not change from when you ran it at the command line (if you did that first), then that suggests that your script is not getting started at all during boot, and that there is a setup piece missing.

mark
the future will be a lot like now, only later
S.K. Chan
Honored Contributor

Re: script problem

When you link it in rc3.d, make sure that's the last startup script. Choose a higher SXXX
number.
harry d brown jr
Honored Contributor

Re: script problem


Does the script require any volumes to be mounted, the network to be up and running, a database to be started? It could be just a matter of boot sequence.

Can you post the script?

live free or die
harry
Live Free or Die
Domenico_5
Respected Contributor

Re: script problem

hi guys

yes, it's the last in rc3.d

On a Workstation whit the same OS all work correctly

James R. Ferguson
Acclaimed Contributor

Re: script problem

Hi (again):

You certainly have a lot of curiosity generated. Several folks have asked you to *please post the script*. Well?

Regards!

...JRF...
Mladen Despic
Honored Contributor

Re: script problem

Domenico,

/sbin/rc3.d/S101nrpe star_msg

and

/sbin/rc3.d/S101nrpe start

are valid tests. You can try rebooting into a single-user mode. Do 'mount -a' and then run the same tests.

The other two commands:

/sbin/rc3.d/S101nrpe stop_msg

and

/sbin/rc3.d/S101nrpe stop

should be replaced by:

/sbin/rc2.d/K899nrpe stop_msg

and

/sbin/rc2.d/K899nrpe stop

respectively.

Mladen
Carlos Fernandez Riera
Honored Contributor

Re: script problem

While you try... put it in /sbin/rc4.d/S100xxx


And then you will do: init 4


insert :

exec 2>/tmp/whatishappening
set -x


on the first lines of your scripts...
if /tmp/whatishappening exists at least you know the script have been executed, and the errors produced...




unsupported
Domenico_5
Respected Contributor

Re: script problem

in attach there is the script

it doesn't use a volume mounted after.

Carlos Fernandez Riera
Honored Contributor

Re: script problem

Ah ...


If you are trying do write something like a daemond you will need to trap HUP signal..


trap - HUP

unsupported
harry d brown jr
Honored Contributor

Re: script problem

Does nrpe restart itself as a daemon?

/usr/local/nrpe/nrpe -d /usr/local/nrpe/nrpe.cfg > /dev/null 2>&1


or should you add the ability to launch this in the background?


live free or die
harry
Live Free or Die
Carlos Fernandez Riera
Honored Contributor

Re: script problem

sorry:


trap "" 1


By the moment comment out :

/usr/local/nrpe/nrpe -d /usr/local/nrpe/nrpe.cfg # > /dev/null 2>&1


unsupported
Mladen Despic
Honored Contributor

Re: script problem

It looks like nrpe may depend on some networking functions.
If so, you won't be able to start it in a single-user mode. But you can do:

init 2

from the single user mode and then test the startup script manually.

Or, as suggested earlier, test it at run level 4.