Page 1 of 1
Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Posted: Wed Mar 13, 2019 9:50 am
by nelsonw
Hi,
I have a command (e.g. myscript.sh) that is executed under nrds.pl via cron. myscript.sh then makes a call to /usr/local/nrdp/clients/send_nrdp.sh.
The send_nrdp.sh script is not getting called from within myscript.sh under cron. When I run myscript.sh direct from the command line, send_nrdp.sh works fine.
The issue appears to be within cron, as if I enter send_nrdp.sh direct in to crontab, it does not execute either. I get the error message
"ERROR: The NRDP Server said BAD XML"
Do I need to explicitly define some environment variables to get this to work
Thanks,
Nelson
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Posted: Wed Mar 13, 2019 10:24 am
by npolovenko
Hello,
@nelsonw. Please show me how you defined the entry in crontab.
Can you also upload the myscript.sh in this ticket?
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Posted: Wed Mar 13, 2019 1:27 pm
by nelsonw
Can you let me know what should be the correct line in send_nrdp.sh
The version I downloaded had
# Detect STDIN
########################
if [ ! -t 0 ]; then
xml=""
But on GitHub, you have
# Detect STDIN
########################
if [[ ! $host && ! $State && ! $file && ! $directory ]]; then
xml=""
When I updated send_nrdp.sh to be inline with GitHub, /usr/local/nrdp/clients/nrds/nrds.pl completed successfully
FYI - My crontab entry is
0,30 * * * * /usr/local/nrdp/clients/nrds/nrds.pl -H '<HOST>'
Entry from /usr/local/nrdp/clients/nrds/nrds.cfg is
command[<Service Name>]=/usr/local/nagios/libexec/<MyScript.ksh>
MyScript.ksh contains the following lines
....
/usr/local/nagios/libexec/<AnotherScript.ksh>
RET=$?
/usr/local/nrdp/clients/send_nrdp.sh -u <NRDP HOST> -t <TOKEN> -H <HOST> -s "<SERVICENAME>" -S $RET -o "`cat $OUTFILE`"
....
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Posted: Wed Mar 13, 2019 1:36 pm
by scottwilkerson
Both actually should work fine, also you aren't using STDIN anyways so it doesn't matter but this is the latest:
nelsonw wrote:Code: Select all
# Detect STDIN
########################
if [[ ! $host && ! $State && ! $file && ! $directory ]]; then
xml=""
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Posted: Thu Mar 14, 2019 5:10 am
by nelsonw
Thanks Scott.
Agreed, I do not use STDIN in my scripts.
Although, it looks like /usr/local/nrdp/clients/nrds/nrds.pl uses STDIN when it calls send_nrdp.
FYI - The below did not work for me
# Detect STDIN
########################
if [ ! -t 0 ]; then
xml=""
I got the error message, "ERROR: The NRDP Server said BAD XML" (as the XML was empty). It appears when calling send_nrdp.sh via
1. Cron job calls /usr/local/nrdp/clients/nrds/nrds.pl
2. nrds.pl executes script, say myScript.ksh
3. myScript.ksh calls send_nrdp.sh-u <NRDP HOST> -t <TOKEN> -H <HOST> -s "<SERVICENAME>" -S $RET -o "<Output>"
send_nrdp.sh will ignore what is passed as parameters in step 3, and looks at STDIN. I think it is because the parent process that is calling send_nrdp.sh is Cron. As a test, if you have
crontab -l
00 * * * * /usr/local/nrdp/clients/send_nrdp.sh -u <NRDP HOST> -t <TOKEN> -H <HOST> -s "<SERVICENAME>" -S $RET -o "<Output>"
the parameters would be ignored and send_nrdp.sh would look at STDIN
Not sure if this was an issue in my set up. Anyway, please close the thread, everything is working ok now I am using
if [[ ! $host && ! $State && ! $file && ! $directory ]]; then
xml=""
Thanks,
Nelson
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Posted: Thu Mar 14, 2019 6:59 am
by scottwilkerson
nelsonw wrote:Not sure if this was an issue in my set up. Anyway, please close the thread, everything is working ok now I am using
Sounds good!
Locking thread