How to run plugin at command line

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
tmattingly
Posts: 115
Joined: Thu Oct 23, 2014 12:53 pm

How to run plugin at command line

Post by tmattingly »

Hello,

This may be documented somewhere but I am trying to run a plugin '.sh' (Bash) script -- check_snmp_printer (and named it with a .sh extension) from https://github.com/ynlamy/check_snmp_printer but I can't seem to run. Though I can see it with LS it reports...
bash: /usr/local/nagios/libexec/check_snmp_printer.sh: /bin/bash^M: bad interpreter: No such file or directory

However I have other .SH plugins that seem to work so I am missing something basic at the command line.

Also (probably a very silly question) but how do you single step through a pearl or bash script? What tools are available to do this?

Thanks,

Tom
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: How to run plugin at command line

Post by benjaminsmith »

Hi Tom,

First, use the Upload a Plugin feature from the Manage Plugins page in Nagios XI so the correct plugin permissions will get set automatically. To upload a plugin, go to Admin > System Extensions >Manage Plugins.
upload-plugin.png
To test a plugin from the command line, follow the instructions are our knowledgebase:

Nagios XI - How To Test Check Commands From The Command-line

Lastly, to execute a bash script in debug mode, run following:

Code: Select all

bash -x your-script.sh
Let us know if you have any other questions or need further assistance.
You do not have the required permissions to view the files attached to this post.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
tmattingly
Posts: 115
Joined: Thu Oct 23, 2014 12:53 pm

Re: How to run plugin at command line

Post by tmattingly »

Thats good and I've been down that path. Apparently after some further testing I had opened up the file on my Windows 10 machine in Notepad++ but when I went to import it I didn't check the box 'Convert line endings' and that really through off Bash.

Tom
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to run plugin at command line

Post by lmiltchev »

That would do it.

FYI, you could check the line endings in Linux when you open your plugin in "vi", by typing:

Code: Select all

:set ff?
and pressing "Enter". You should see:

Code: Select all

fileformat=unix
If you see "dos", then you would need to convert it.

Code: Select all

:set ff=unix
press Enter, then save the file and exit:

Code: Select all

:wq
Let us know if it is OK to close this topic. Thanks!
Be sure to check out our Knowledgebase for helpful articles and solutions!
tmattingly
Posts: 115
Joined: Thu Oct 23, 2014 12:53 pm

Re: How to run plugin at command line

Post by tmattingly »

Last question, what is the best tools to use to debug a pearl or bash script?

Beyond that, YES close the thread.

Tom
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to run plugin at command line

Post by lmiltchev »

You can run a bash script with "-x", and perl script with "-d" in order to debug them.

Example:

Code: Select all

bash -x /path/to/bash_sciprt.sh
perl -d /path/to/perl_script.pl
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked