Version 12 (modified by pharoz, 12 months ago) (diff)

--

Example of a .cmd-script

This is unsupported user provided content, if you have issues you are on your own :)


SERVER\SHARE$ is where you keep the script, RoboCopy? and the NSClient++ files

@echo off
echo map drive
net use I: \\SERVER\SHARE$\NSClient++ /persistent:no
I:
echo.
echo Install NSClient++
if not exist "C:\Program Files\NSClient++\NSClient++.exe" goto skip01
echo removing old version
"C:\Program Files\NSClient++\NSClient++.exe" /stop
"C:\Program Files\NSClient++\NSClient++.exe" /uninstall
rmdir /s /q "C:\Program Files\NSClient++


:skip01
echo.
echo install latest version
mkdir "C:\Program Files\NSClient++
I:\robocopy /MIR I: "C:\Program Files\NSClient++"
"C:\Program Files\NSClient++\NSClient++.exe" /install
"C:\Program Files\NSClient++\NSClient++.exe" /start
c:
echo.
echo Unmap drive
net use I: /DELETE

Updating NSClient++

This set of script will allow you to sync your files from a centralize share to your NSClient++ install folder with logging info. After a successful copy, it will launch another batch script instance (reload.bat) to restart the NSClient++ service for the changes to take effect. You can then create a service command in Nagios to run the NRPE plugin script to have it automatically sync your NSClient++ folder. If it fails/pass, it'll even output the info along with what rev it was pulling.

Tested on Windows XP/2003/2008(32/64-bit) clients.

Place both of these scripts in the script folder and create an entry in your NSC.ini for them. Make sure you modify the source variable to reflect your central share.

Your central share should have a folder structure like this:
\           (Place your NSC.ini here)
\scripts\   (Place your scripts here)

update.bat

@echo off
@setlocal enableextensions
@cd /d "%~dp0"

REM Variables
set source=\\your\share
set rev=1.0

REM Copying scripts
echo %date%-%time% >> check_script_update.log
copy "%source%\scripts\*.*" "%PROGRAMFILES%\NSClient++\scripts" /y >> check_script_update.log
copy "%source%\*.*" "%PROGRAMFILES%\NSClient++\" /y >> check_script_update.log
CLS
@echo off

IF ERRORLEVEL 1 GOTO err
IF ERRORLEVEL 0 GOTO ok
GOTO unknown
 
:err
echo CRITICAL: Script copy failed: rev %rev%
exit /B 1
 
:unknown
echo UNKNOWN: Something went wrong: rev %rev%
exit /B 3
 
:ok
echo OK: Script copy succeeded: rev %rev%
start reload.bat
exit /B 0

reload.bat

@echo off
@setlocal enableextensions
@cd /d "%~dp0"

"%PROGRAMFILES%\NSClient++\nsclient++.exe" -stop
"%PROGRAMFILES%\NSClient++\nsclient++.exe" -start
EXIT