Check Memory Plugin Issue - check_mem.pl

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
User avatar
sushant4tech
Posts: 25
Joined: Fri Jul 31, 2015 12:24 am

Check Memory Plugin Issue - check_mem.pl

Post by sushant4tech »

Hi All,

I download the "check_mem.pl" from 'exchange.nagios.org' or the link https://raw.githubusercontent.com/justi ... eck_mem.pl. This plugin is to check the available memory (RAM) of the host. I copied this perl script to my library plugin folder "/usr/lib/nagios/plugins/" and added execute rights to the file.

Code: Select all

sudo chmod +x /usr/lib/nagios/plugins/check_mem.pl 
Then checked it manually and got the expected results. the only issue was that the results were shown in KB and i wanted it to display it in MB. I did some changes (which were useless as i dont have any knowledge of perl) and then some time later i stopped getting output completely.

I knew i messed up so i again replaced the messed up perl script with the original code from link above. But it didnt work. I tried this on different nagios instance with original script but strangely i got the same error on that instance as well. Please check the code below and suggest whats going wrong.

Code: Select all

ubuntu@ip-XXX-XX-X-XX:/etc/nagios3/conf.d$ /usr/lib/nagios/plugins/check_mem.pl -w 10 -c 5 -f -C
/usr/lib/nagios/plugins/check_mem.pl: line 1: #!/usr/bin/perl: No such file or directory
/usr/lib/nagios/plugins/check_mem.pl: line 2: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 10: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 16: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 19: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 26: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 28: use: command not found
/usr/lib/nagios/plugins/check_mem.pl: line 28: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 29: use: command not found
/usr/lib/nagios/plugins/check_mem.pl: line 29: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 30: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 33: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 35: syntax error near unexpected token `('
'usr/lib/nagios/plugins/check_mem.pl: line 35: `use vars qw($opt_c $opt_f $opt_u $opt_w $opt_C $opt_v %exit_codes);
- $u$h@nT
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Check Memory Plugin Issue - check_mem.pl

Post by hsmith »

sushant4tech wrote:Hi All,

I download the "check_mem.pl" from 'exchange.nagios.org' or the link https://raw.githubusercontent.com/justi ... eck_mem.pl. This plugin is to check the available memory (RAM) of the host. I copied this perl script to my library plugin folder "/usr/lib/nagios/plugins/" and added execute rights to the file.

Code: Select all

sudo chmod +x /usr/lib/nagios/plugins/check_mem.pl 
Then checked it manually and got the expected results. the only issue was that the results were shown in KB and i wanted it to display it in MB. I did some changes (which were useless as i dont have any knowledge of perl) and then some time later i stopped getting output completely.

I knew i messed up so i again replaced the messed up perl script with the original code from link above. But it didnt work. I tried this on different nagios instance with original script but strangely i got the same error on that instance as well. Please check the code below and suggest whats going wrong.

Code: Select all

ubuntu@ip-XXX-XX-X-XX:/etc/nagios3/conf.d$ /usr/lib/nagios/plugins/check_mem.pl -w 10 -c 5 -f -C
/usr/lib/nagios/plugins/check_mem.pl: line 1: #!/usr/bin/perl: No such file or directory
/usr/lib/nagios/plugins/check_mem.pl: line 2: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 10: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 16: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 19: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 26: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 28: use: command not found
/usr/lib/nagios/plugins/check_mem.pl: line 28: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 29: use: command not found
/usr/lib/nagios/plugins/check_mem.pl: line 29: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 30: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 33: $'\r': command not found
/usr/lib/nagios/plugins/check_mem.pl: line 35: syntax error near unexpected token `('
'usr/lib/nagios/plugins/check_mem.pl: line 35: `use vars qw($opt_c $opt_f $opt_u $opt_w $opt_C $opt_v %exit_codes);
What does the output of a ls -l /usr/bin | grep perl command look like?

Can you post the contents of the plugin, as it is on your server (preferably without your modifications :P) in code brackets here?
Former Nagios Employee.
me.
User avatar
sushant4tech
Posts: 25
Joined: Fri Jul 31, 2015 12:24 am

Re: Check Memory Plugin Issue - check_mem.pl

Post by sushant4tech »

Hey Smith,
What does the output of a ls -l /usr/bin | grep perl command look like?

Code: Select all

ubuntu@ip-172-30-1-13:/usr/bin$ ls -l /usr/bin | grep perl
-rwxr-xr-x 1 root   root        545 Mar 27  2014 cpanp-run-perl
-rwxr-xr-x 1 root   root      23599 Mar 27  2014 find2perl
-rwxr-xr-x 2 root   root      10416 Mar 27  2014 perl
-rwxr-xr-x 2 root   root      10416 Mar 27  2014 perl5.18.2
-rwxr-xr-x 2 root   root      41774 Mar 27  2014 perlbug
-rwxr-xr-x 1 root   root        125 Mar 27  2014 perldoc
-rwxr-xr-x 1 root   root      10823 Mar 27  2014 perlivp
-rwxr-xr-x 2 root   root      41774 Mar 27  2014 perlthanks
Can you post the contents of the plugin, as it is on your server (preferably without your modifications :P) in code brackets here?
The first line of the script is:

Code: Select all

#!/usr/bin/perl -w
The complete script is exactly the same as in the link below.
https://github.com/justintime/nagios-pl ... ck_mem.php

To add i did run the same script earlier and got desired output, but idk what happened later. :roll:
- $u$h@nT
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Check Memory Plugin Issue - check_mem.pl

Post by Box293 »

sushant4tech wrote:I knew i messed up so i again replaced the messed up perl script with the original code from link above.
Exactly how did you do that? Copy from screen and paste into vi or nano in SSH session?

If you did this there can be windows/linux file issues with end of lines.

I would delete the plugin and scp it across. If you've already done this, try dos2unix <filename> and it should fix the file.

Does that help?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
sushant4tech
Posts: 25
Joined: Fri Jul 31, 2015 12:24 am

Re: Check Memory Plugin Issue - check_mem.pl

Post by sushant4tech »

Hey Box,

Thanks bro. I did copy the file using Winscp...

Code: Select all

If you've already done this, try dos2unix <filename> and it should fix the file.
worked.
Thanks a mil...
- $u$h@nT
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Check Memory Plugin Issue - check_mem.pl

Post by hsmith »

sushant4tech wrote:Hey Box,

Thanks bro. I did copy the file using Winscp...

Code: Select all

If you've already done this, try dos2unix <filename> and it should fix the file.
worked.
Thanks a mil...
Glad that one worked. I'm going to go ahead and mark this thread resolved.
Former Nagios Employee.
me.
Locked