Operating System - HP-UX
1830899 Members
3266 Online
110017 Solutions
New Discussion

Would appreciate debugging tips for SD configure script

 
Ralph Grothe
Honored Contributor

Would appreciate debugging tips for SD configure script

Hi,

I try to swpackage a Nagios NRPE build.
Because service needs to be registered,
group and user added and inetd reconfigured
I provided a configure/unconfigure script
in which I cannot find a syntax error.
There must be some garbage in the configure file however.
Though I tried "cat -e configure" and "xd -t a configure" I cannot find the following number LF sequences that seem to cause the syntax error.

When I run
# swconfig NagiosNRPE.ALL

in swjob's log it failed with this line

/var/adm/sw/products/NagiosNRPE/ALL/configure[23]: 27^J35^J40^J52^J59^J75^J91^J1
01^J102^J109^J112: Syntax error

I slightly modified the script to use $$ instead o jobid parsed from $SW_SESSION_OPTS to be able to run the script from the interactive shell as well.
So when I set -x and provide the minimally required SW environment I get the same result.

# SW_PATH=/usr/bin SW_SOFTWARE_SPEC=NagiosNRPE.ALL,bla SW_CONTROL_TAG=configure /var/adm/sw/products/NagiosNRPE/ALL/configure
+ export PATH=/sbin:/usr/sbin:/usr/bin
+ + uname -n
NODE=elba
+ fileset=NagiosNRPE.ALL
+ [[ -n ]]
+ JOBID=7896
+ [[ NagiosNRPE.ALL = NagiosNRPE.ALL ]]
+ eval_response
+ : 5666
+ 1>& 2
+ has_listen_socket 5666
+ configure_inetd
/var/adm/sw/products/NagiosNRPE/ALL/configure[23]: 27^J35^J40^J52^J59^J75^J91^J101^J102^J109^J112: Syntax error

Is there a better way to debug this?
Madness, thy name is system administration
13 REPLIES 13
Dennis Handly
Acclaimed Contributor

Re: Would appreciate debugging tips for SD configure script

What's on line 23?
Is configure_inetd a function?

You'll need to insert "set -x" in each function you use.
(I don't know if "#!/sbin/sh -x" will work for the whole script?)

The error looks like you are doing: $(< file)
With a missing command in the front.
Ralph Grothe
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

Not being too happy with sh's debugging facilities,
would anything prohibit writing those swpackage scripts in Perl?
I really cannot find a compelling reason.
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

Hi Dennis,

yes, configure_inetd is a func,
and yes, I haven't put -x in every func's body.

I think the reference to line 23 is bogus.
There isn't something evil around it.
Only my quick fix for an undefined $SW_SESSION_OPTIONS, which is merely an ephemeral file provided in swconfig's context.

# cat -n -e -t /var/adm/sw/products/NagiosNRPE/ALL/configure|sed -n 20,25p
20 if [[ -n $SW_SESSION_OPTIONS ]]; then$
21 JOBID=$(awk -F'[= ]' '$1=="jobid"{print$2}' $SW_SESSION_OPTIONS)$
22 else$
23 JOBID=$$$
24 fi$
25 $
Madness, thy name is system administration
Dennis Handly
Acclaimed Contributor

Re: Would appreciate debugging tips for SD configure script

>would anything prohibit writing those swpackage scripts in Perl?
>I really cannot find a compelling reason.

Several:
1) Perl may not be installed on all systems.
2) You need /sbin/sh when /usr/ isn't mounted.
3) How will you use the functions in /usr/lbin/sw/control_utils?
4) You shouldn't be writing buggy shell code. :-)
Ivan Krastev
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

Hello Ralph,

Have you tried with SDU_DEBUG options?

Try to export to appropriate level (1-4) and after that try swconfig commands.

regards,
ivan
Dennis Handly
Acclaimed Contributor

Re: Would appreciate debugging tips for SD configure script

>I think the reference to line 23 is bogus.

It may mean line 23 in that function. What were the lines for:
+ has_listen_socket 5666
+ configure_inetd

>Ivan: Have you tried with SDU_DEBUG options?

I'm not sure that is any better than "set -x" or "#!/sbin/sh -x". And it probably equal to the latter.
Ralph Grothe
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

Hello Ivan,

no I haven't yet come across SDU_DEBUG.
Can't remember to have seen it in any of the manpages.
That thing is quite nice.
But I think it is rather addressed at the developers of SD utils and not the user to debug their crappy scripts.
Even with highest flag it doesn't produce more hints related to the script error.

# SDU_DEBUG=4 swconfig NagiosNRPE.ALL 2>&1|grep ERR
ERROR: "elba:/": 1 configure or unconfigure scripts failed.
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

Since you asked for the ugly details.

I admit, probably too contrived
where a mere grep would have done.

has_listen_socket() {
netstat -an -f inet \
| awk -v p=${1:-5666} 'BEGIN{rc=1}; \
$1=="tcp"&&$NF=="LISTEN"&&a[split($4,a,".")]==p{rc=0;exit}; \
END{exit rc}'
}
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

I discovered an interesting effect
which makes me suspect that the failure could have been cause by an absent response file.
I provided my script with a request block
which of course only gets executed when swinstall or swconfig is run with -x ask=true.

So this time I invoked swconfig with that option an confirmed my request defaults.
This time all has been configured to my delight and inetd started the new service.

[root@elba:/root]
# netstat -an|grep 5666
tcp 0 0 *.5666 *.* LISTEN
[root@elba:/root]
# id nagios
uid=103(nagios) gid=102(nagios)
[root@elba:/root]
# grep nagios /etc/passwd
nagios:*:103:102:NRPE user added by SD elba-0089:/var/opt/nagios:/usr/bin/sh
[root@elba:/root]
# grep nrpe /etc/{services,inetd.conf}
/etc/services:nrpe 5666/tcp # Nagios Remote Plug-in Executor
/etc/inetd.conf:nrpe stream tcp nowait nagios /opt/nagios/sbin/nrpe nrpe -n -c /opt/nagios/etc/nrpe.cfg -i

[root@elba:/root]
# /opt/nagios/plugins/libexec/check_nrpe -n -H 127.0.0.1 -c check_disk
DISK CRITICAL - /export/oracle/arch1 is not accessible: Berechtigung verweigert

Ok, the failing check_disk reminds me that I still need to build in some sudo rule for non-readable,executable mount points by the nrpe user.


Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

Can anyone tell me how I should provide a predefined reponse file,
in case that the person installing the depot doesn't want to run through request with -x ask=true because they are happy with the defaults?

I mean I can't put it in advance into
$SW_CONTROL_DIRECTORY/response
could I?

I have't yet understood how to supply a preset response file.
Madness, thy name is system administration
Dennis Handly
Acclaimed Contributor

Re: Would appreciate debugging tips for SD configure script

has_listen_socket() {
netstat -an -f inet \
| awk -v p=${1:-5666} 'BEGIN{rc=1}; \
$1=="tcp"&&$NF=="LISTEN"&&a[split($4,a,".")]==p{rc=0;exit}; \
END{exit rc}'
}

You have too many "\". :-)
The first, you can remove the "\" and put the "|" at the end of the line.
You don't need any "\" inside the awk single quotes.

has_listen_socket() {
netstat -an -f inet |
awk -v p=${1:-5666} '
BEGIN {rc=1}
$1=="tcp" && $NF == "LISTEN" && a[split($4,a,".")] == p {
rc=0
exit
}
END {exit rc}'
}

You might want to add an echo before and after that one pipeline.
Dennis Handly
Acclaimed Contributor

Re: Would appreciate debugging tips for SD configure script

>cause by an absent response file.

You should use "set -u" to check for uninitialized shell variables?
Ralph Grothe
Honored Contributor

Re: Would appreciate debugging tips for SD configure script

Thanks Dennis,

I am not terribly fond of awk and regard only as an inferior makeshift when one cannot expect to find perl.
That's why I never have invested too much bother on quoting voodoo in awk.
In perl we have the -MO=Deparse if we want to look behind the scenes.

Yes, I will take up the -u to aid in debugging.
Madness, thy name is system administration