Page 1 of 1

How to run plugin at command line

Posted: Mon Feb 17, 2020 5:07 pm
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

Re: How to run plugin at command line

Posted: Mon Feb 17, 2020 5:22 pm
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.

Re: How to run plugin at command line

Posted: Mon Feb 17, 2020 5:39 pm
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

Re: How to run plugin at command line

Posted: Mon Feb 17, 2020 5:48 pm
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!

Re: How to run plugin at command line

Posted: Mon Feb 17, 2020 5:56 pm
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

Re: How to run plugin at command line

Posted: Mon Feb 17, 2020 6:02 pm
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