AlexNogard: IT HowTo

Linux & Opensource : Monitoring : Centreon, Nagios, Owncloud ..


Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!

Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!,An error that comes up from time to time and is quite annoying to deal with, I found a way to fix the problem, it is not the best way, but it is simple and fast.

Explanation: when nagios starts, it creates a file that will run nagios.cmd our services, excluding, for some, bad rights are granted, the right permissions being 666.

We could grant the nagios rights with a simple chmod, but the problem is that each restart, the nagios.cmd recreates itself … We’ll go through a little hack:

vim /etc/init.d/nagios

Below :

 chown $NagiosUser:$NagiosGroup $NagiosRunFile
$NagiosBin -d $NagiosCfgFile

Add :

bash /root/

Save & quit, then :

# vi /root/
// Add the following lines :

sleep 10
chmod 666 /usr/local/nagios/var/rw/nagios.cmd

// save & quite

chmod 755

Whenever you restart your nagios our little script will run and give right permissions to our nagios.cmd

If you have any questions or comments, the comments are there for that 😉

Feel free to share this article with share buttons !

9 Responses to Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

  1. javy says:

    Sorry, i don’t speak french and google translate doesn’t help me a lot….:( , can’t understand the first step.

    By the way i make a little .sh to execute every time that nagios restart

    but i want to launch when nagios start


    • Dear Javy,
      As explained, you have to open /etc/init.d/nagios,
      And add the following line : bash /root/

      after :
      chown $NagiosUser:$NagiosGroup $NagiosRunFile
      $NagiosBin -d $NagiosCfgFile

      Hope I helped you 😉

  2. breaker says:

    nice, just to add before you run that “chmod 755”
    need to run in /root 1st…
    noob here…LoL

  3. Gary says:

    This worked great!!


  4. Ryan N. says:

    Really bad idea! 666 is “anyone on system could write to it”! The real solution is to make sure your webserver is part of the group that owns this file. You should correct this right away as this is a potential security problem on a multiuser system.

  5. zent00 says:

    no need to chmod 666 /usr/local/nagios/var/rw/nagios.cmd
    Just add apache to nagios group and restart apache

  6. zent00 says:

    OOps. Did not see Ryan N comment…

  7. zent00 says:

    no need to “restart” apache, “reload” is sufficient.

  8. Fernando Garza says:

    Solved with: usermod -G nagcmd www-data
    and restarting.

Leave a Reply

Your email address will not be published. Required fields are marked *