How to Fix the Bad Interpreter No Such File or Directory Error in Nagios?

How to Fix the Bad Interpreter No Such File or Directory Error in Nagios?

If you’re seeing the Bad interpreter error in Nagios, then you’re not alone. It’s a common problem faced by admins managing Windows environment. Generally, you get the bad interpreter error when porting scripts from your Windows environment to a Unix format. In this article, learn how to fix it.

nagios.png


How to Fix the Bad Interpreter No Such File or Directory Error?

As already mentioned, the problems occurs when you create scripts in Windows before porting them over to Unix systems. A deeper, more actionable problem is the file that was in Windows was in the Windows format. Once ported over to Unix, the format stays the same.

So to resolve the issue, you need to covert the file into a Unix format. For that, open your SSH port and execute a few commands with root privileges.

Before that, you need to install the packages that are necessary. Execute these first:

Code:
RHEL|CentOS
yum install -y dos2unix
Code:
Debian|Ubuntu
apt-get install -y dos2unix
Now, you can get started with converting the file to Unix. Enter this command for that:

Code:
dos2unix /usr/local/nagios/libexec/check_apc_pdu_load.sh
Upon executing, you should get the following output:

Code:
dos2unix: converting file /usr/local/nagios/libexec/check_apc_pdu_load.sh to UNIX format …
Once the process is completed, the plugin will work as it should have been.

Another way to fix this issue (which is a bit complicated) is by rewriting the script. You can do this in the Unix environment using a text editor.

If you want to rewrite it on Windows, ensure the editor is set to output the files as UNIX format.

If you’re using Notepad++, you should find an option in the bottom right hand side of the screen which would tell you the document format. By default, it will be set to Dos/Windows. You need to change it to Unix.

So for this, you need to follow this instruction - Settings >> preferences >> new document/default directory tab >> select the format as unix and close >> create a new document

You need to remove the CR character using this command:
Code:
sed -i -e ‘s/\r$//’ NAME-OF-FILE.sh
So that’s how you resolve this issue. For further assistance, get in touch with your hosting provider.
Author
kumkumsharma
Views
6,321
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top