Runs at command line but doesn't run when...
Any time this occurs the most likely issue is environment. When you login you are invoking things like /etc/profile, /etc/bashrc, /etc/bashprofile, $HOME/.profile, $HOME/.bashrc and/or $HOME/.bash_profile to condition your environment. These things set many environment variables chief among which is $PATH which tells it where to look for executables when you give a short name. (For example if the ls command is in /bin your PATH variable would need to include /bin for you to be able to just type "ls" rather than having to type "/bin/ls" every time.) However there are other important variables as well. When you run Nagios (or cron or any other background process) it isn't logging in so typically does NOT invoke the above files. That means you have to insure the background process knows what environment settings it should have - the best way to do that is to include them in the script.
So if you add a line to the script to output the env to a file and run it from command line then again from Nagios you can find what the environmental differences are between the two runs.