I have a custom script sensor that runs a simple batch file that looks inside a txt file and then checks errorlevel variable for 0, 1, or 2+.
this script runs perfectly fine when executed from the command line on the machine.
PRTG though when running it, shows that it simply isn't running the "Find" command at all, but its not treating it like a bad command.
Here's the output I'm seeing that illustrates the problem:
- Here I run di as an incorrect command, and I get this error so I know its not a problem that PRTG doesn't see the Find command.
C:\XxXxXxXx\Scripts\backup\logs>di 'di' is not recognized as an internal or external command, operable program or batch file.
C:\XxXxXxXx\Scripts\backup\logs>echo.%errorlevel% 9009
- Here is the find command, set to ignore case and find the word Error in the log file in that directory. C:\XxXxXxXx\Scripts\backup\logs>find /I "Error" test.log
- This error level is for when it doesn't find anything, but there's no output from Find which isn't normal, you can see normal output from Find below. C:\XxXxXxXx\Scripts\backup\logs>echo.%errorlevel% 1
Below is the same command, run from the command line of the machine.
C:\XxXxXxXx\Scripts\backup\logs>find /I "Error" test.log
- This TEST.LOG line should be showing if the command is able run at all.
---------- TEST.LOG This is a perfectly good Error backup log.
I have other commands all referencing this file in the same script, and all are finding it. It is only the FIND commands that are exhibiting this odd behavior of no output, error code to 1.
I've given the script the full path to the file, and tested that the DIR command before the FIND was in the right directory, so I know it can see the file.
Any help would be appreciated.
Article Comments
After some trial an error I've found that for what ever reason, PRTG or the system wouldn't run the FIND command correctly, but when I switched to FINDSTR I was able to get the script working again with correct output.
The original script still works fine with FIND when run from a command prompt, and works with FINDSTR too, it was simply when being run from PRTG probe that it proved unusable.
One caveat would be that if I used a FOR loop to run the find command, it would run, but always report the file wasn't found even with full path given, and because I'm just checking errorlevel output, not usable as I'd only be able to check the errorlevel of the FOR command.
For reference, this was on a SBS2003 server and using just a simple batch file script.
Sep, 2011 - Permalink
Hello,
please check if it makes any difference if the PRTG Probe Service runs under your account (or an admin account) just like when you execute the script yourself. Furthermore, please be aware that it might be necessary to specifically define the paths in scripts used by PRTG, do not use relative paths. And please also be aware that the Custom Script sensors have an option in their "Settings" to write their last result as a log onto the harddrive.
best regards.
Sep, 2011 - Permalink