Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to check number of MySQL databases. I've created simple test "plugin":

Location: `/var/lib64/nagios/plugins



db=$(mysql -e 'SHOW DATABASES' | wc -l)
echo $db

It works from the local machine:

# ./test 
  • however when executed from Nagios server it displays "0"

NRPE config:


Nagios server:

# ./check_nrpe -H -c "test"


share|improve this question
Log the output of the db=$(mysql -e 'SHOW DATABASES' | wc -l) to a file. Possibly mysql is not in $PATH and/or the user as which it runs has no access to MySQL. – faker Jun 27 '12 at 12:28
Has the nagios user access to run the mysql command without any passwords etc? Try with su! – HampusLi Jun 27 '12 at 13:08
up vote 3 down vote accepted

NPRE commands usually run as nagios. It seems like your query is actually polling how many databases your nagios user can see.

There are several solutions to your problem:

  • Add user and password information to your command (mysql -uroot -proot -e 'SHOW DATABASES' | wc -l);
  • Add nagios to your sudoers file, so that he can run mysql as root (nagios ALL=(ALL) NOPASSWD:/usr/bin/mysql -e 'SHOW DATABASES');
  • Add a nagios user to your database with sufficient permissions to see all databases (mysql documentation) - RECOMMENDED;
share|improve this answer

BTW, you should consult as the output from the shown in your plug-in script is quite non-standard for Nagios andf will cause problems.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.