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 currently have the following script on a Windows Server:

@echo off
set path=%PATH%;C:\UnxUtils\usr\local\wbin

cd /D Z:\videos

forfiles /M *_1.mkv /D +%date% > C:\mkv.txt >NUL 2>&1
FOR /F "tokens=*" %%B IN ('grep -c _1.mkv c:\mkv.txt') DO SET VIDEOS=%%B

if %VIDEOS% GEQ 1 (
echo "BAD VIDEOS!"
exit /B 0
) else (
echo "Videos OK"
exit /B 1 )

I need Nagios to check if the scripts exit code is 0 or 1 to diplay a critical alert or a ok. Is this possible?

share|improve this question
up vote 1 down vote accepted

Actually, that's what Nagios does. You need to return the correct return codes, though. You'll probably have to change your script like this:

if %VIDEOS% GEQ 1 (
  echo "BAD VIDEOS!"
  exit /B 2
) else (
  echo "Videos OK"
  exit /B 0
share|improve this answer
Thanks. I also had a problem on this " >NUL 2>&1 ". So the mkv.txt file what never filled. Now it is working. – Kevin Maschke Sep 4 '12 at 13:06

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.