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
Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
-
npolovenko
- Support Tech
- Posts: 3457
- Joined: Mon May 15, 2017 5:00 pm
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Hello, @nelsonw. Please show me how you defined the entry in crontab.
Can you also upload the myscript.sh in this ticket?
Can you also upload the myscript.sh in this ticket?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
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`"
....
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`"
....
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
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
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
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
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Calling /usr/local/nrdp/clients/send_nrdp.sh in Crontab
Sounds good!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
Locking thread