Operating System - HP-UX
1752600 Members
3833 Online
108788 Solutions
New Discussion

Re: script is producing garbage at end

 
Rick Garland
Honored Contributor

script is producing garbage at end

Hi all:

 

Using nagios 3.2.3 to monitor services. Trying to run a script for monitoring. Problem is that on HPUX 11.23 & 11.31 systems the script produces garbage output at the end. Example, here is the script

  • #!/bin/ksh
  • WAITIO=`sar -i 1 3 | tail -1 | awk '{print $4}'`
  • CRIT=50
  • echo "%waitio = $WAITIO | /=$WAITIO%;;$CRIT;0;100"
  • exit 0

And the output

[nagios@nagserver ~]$ check_nrpe -H hostname -c 'check_HPwait'

  • %waitio = 6 | /=6%;;50;0;100
  • ��w���

See that garbage at the end? How do I prevent that from happening on the HP systems?

 

Many thanks!

9 REPLIES 9
James R. Ferguson
Acclaimed Contributor

Re: script is producing garbage at end

Hi Rick:


@Rick Garland wrote:
  • ��w���

See that garbage at the end? How do I prevent that from happening on the HP systems?

 


It's not clear to me if this is a mangled representation on the new Forum or not.  Could you show us what you have pasted into a code-block to prevent interpretation?  Could you pipe your script's output into 'cat -etv' or 'od -tax2' please?
Regards!
...JRF...
donna hofmeister
Trusted Contributor

Re: script is producing garbage at end

i wonder if the problem isn't actually over on the nagios server.  this line

           %waitio = 6 | /=6%;;50;0;100

has a very nagios-look to it and running the bit of script by-hand on hpux doesn't produce any strange characters (at least for me).  is 'waitio' a(nother) nagios script?  are the spaces before/after the 1st equal sign problematic?  or even all the spaces on that line?

Dennis Handly
Acclaimed Contributor

Re: script is producing garbage at end

There should be no output after your last echo.

Unless that sar call is sending output to stderr?

 

Why don't you redirect your stdout and stderr for your script and see where the garbage goes?

your-script > stdout 2> stderr

 

Otherwise tusc is your friend.

 

Rick Garland
Honored Contributor

Re: script is producing garbage at end

The piped output

[nagios@nagserver libexec]$ check_nrpe -H hostname -c 'check_HPwait' | cat -etv
%waitio = 2 | /=2%;;50;0;100^M$
$
M-(wM-}M-3M-^XwM-}M-3M-^X@^AM-_M-l@$
Rick Garland
Honored Contributor

Re: script is producing garbage at end

Thank you all, you have provided some more ideas for me.

 

My suspicions are with the nrpe agent on the HPUX systems. I did download the source and compile on HP using the HP compiler.

 

I can run similar sar commands via nrpe to Linux systems without the funky output. And I can run the same command locally without the funky output.

 

I tried redirecting, no joy.

 

 

 

 

James R. Ferguson
Acclaimed Contributor

Re: script is producing garbage at end

Hi (again) Rick:

 

I suppose we could band-aid the wound:

 

# check_nrpe -H hostname -c 'check_HPwait' | perl -pe 's/[^([:print:]|[:space:]]//g'

 

Regards!

 

...JRF...

Dennis Handly
Acclaimed Contributor

Re: script is producing garbage at end

>I did download the source and compile on HP using the HP compiler.

 

Then dust off your debugger and find that print at the end.

tusc could be used to see if that garbage is a separate write or part of a buffer.

Rick Garland
Honored Contributor

Re: script is producing garbage at end

Hi all:

 

I tried the band aid; perl, sed, tr - still there.

Interesting, I did find that if I nest the command in a conditional of some sort, ( if,then ) then the output is clean.

Example;

 

  • !/bin/ksh
  • CRIT=50
  • WAITIO=`sar -i 1 3 | tail -1 | awk '{print $4}'`
  • if [ "$WAITIO" -ge "$CRIT" ]
  • then
  •   echo "%waitio = $WAITIO | /=$WAITIO%;;$CRIT;0;100"
  •   exit 2
  • else
  •   echo "%waitio = $WAITIO | \=$WAITIO%;;$CRIT;0;100"
  • fi

Run the command and pipe through 'cat -etv' and all that's left is a $ sign at the end of the output, the rest of the garbage is gone. Any idea why this might be?

 

tusc is definitely an option I should explore. And definitely one I should have in my toolbox.

 

Many Thanks

 

Dennis Handly
Acclaimed Contributor

Re: script is producing garbage at end

>I did find that if I nest the command in a conditional of some sort

 

The only difference is that exit.  Do you cover both paths and both eliminate the garbage?

Make sure you print out the exit status of each run or change the one of the messages.