I have the following, which works, but it just got me wondering if this can be concatenated or be written in a more graceful way? By that, I don’t mean getent: database=passwd, key=nagios
If it were my code, i’d probably instead of checking for the nagios user existing, check that the package is installed ( ie rpm -q and register output), or do a stat on the /usr/local/nagios/etc directory and copy the file if is exists… its not a whole lot compact or cleaner than what you have, but it at least wont fail if for some reason you have a nagios user on a box, but dont have the directory structure in place such as your current code. In your example, if the nagios user is there, it assumes that the /usr/local/nagios/etc path exists as a landing pad for your nrpe.cfg file.
Since i dont know what is you install nrpe via a package manager, below is an example using stat to check for the etc directory