Page 1 of 1

Please help - analize batch results and reboot if required.

Posted: 21 Apr 2014 17:49
by dphillips26
Hi there,

I'm trying to write a batch file that that will analise a set of results and reboot if a problem is found in the results.

To explain, I have a graphics driver that fails to load every now and then and would like the machine to auto reboot on a failure.

I've tried using task scheduler to reboot on a system event, but as the event occurs before task scheduler has booted, it does not see it.

I can execute a batch file on system startup to interogate the graphics driver, the part I'm struggling with is analising the results and rebooting if a problem is found.

The command I am using is: devcon status *VEN_DADA* which returns the following results:

PCI\VEN_DADA&DEV_0150&SUBSYS_1150DADA&REV_00\5&38C677BD&0&000038
Name: eyevis NPX-4800-DVI2-2
Driver is running.
PCI\VEN_DADA&DEV_0150&SUBSYS_1150DADA&REV_00\5&38C677BD&0&200038
Name: eyevis NPX-4800-DVI2-2
Driver is running.
PCI\VEN_DADA&DEV_0150&SUBSYS_1150DADA&REV_00\5&13AF8972&0&000028
Name: eyevis NPX-4800-DVI2-2
The device has the following problem: 37
PCI\VEN_DADA&DEV_0150&SUBSYS_1150DADA&REV_00\5&13AF8972&0&200028
Name: eyevis NPX-4800-DVI2-2
The device has the following problem: 37
PCI\VEN_DADA&DEV_0150&SUBSYS_1150DADA&REV_00\5&29635535&0&000048
Name: eyevis NPX-4800-DVI2-2
Driver is running.
PCI\VEN_DADA&DEV_0150&SUBSYS_1150DADA&REV_00\5&29635535&0&200048
Name: eyevis NPX-4800-DVI2-2
Driver is running.
6 matching device(s) found.


how can I analise these results and reboot the machine if the "problem" is found? (problem is highlighted in bold above)

I believe the FOR /F command would work but I can't figure it out.

I would really appreciate any help.

Kind Regards,
Dave

Re: Please help - analize batch results and reboot if requir

Posted: 21 Apr 2014 23:41
by Magialisk
This is as quick and dirty as it gets, but it should get you started:

Code: Select all

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=*" %%a IN ('"devcon status *VEN_DADA*"') do (
   echo "%%a" | find "The device has the following problem:" >nul
   IF !ERRORLEVEL!==0 (
      echo here is where you would shut down
      rem I did not test this part on my own machine, but this FOR/IF skeleton should work.
      rem Use something like one of these commands http://www.robvanderwoude.com/shutdown.php
   )
)
In order to test it, since I don't have this utility called 'devcon', I simply created a batch file named 'devcon.bat' which echoes the text from your example:

Code: Select all

@echo off
echo PCI\VEN_DADA^&DEV_0150^&SUBSYS_1150DADA^&REV_00\5^&38C677BD^&0^&000038
echo Name: eyevis NPX-4800-DVI2-2
echo Driver is running.
echo PCI\VEN_DADA^&DEV_0150^&SUBSYS_1150DADA^&REV_00\5^&38C677BD^&0^&200038
echo Name: eyevis NPX-4800-DVI2-2
echo Driver is running.
echo PCI\VEN_DADA^&DEV_0150^&SUBSYS_1150DADA^&REV_00\5^&13AF8972^&0^&000028
echo Name: eyevis NPX-4800-DVI2-2
echo The device has the following problem: 37
echo PCI\VEN_DADA^&DEV_0150^&SUBSYS_1150DADA^&REV_00\5^&13AF8972^&0^&200028
echo Name: eyevis NPX-4800-DVI2-2
echo The device has the following problem: 37
echo PCI\VEN_DADA^&DEV_0150^&SUBSYS_1150DADA^&REV_00\5^&29635535^&0^&000048
echo Name: eyevis NPX-4800-DVI2-2
echo Driver is running.
echo PCI\VEN_DADA^&DEV_0150^&SUBSYS_1150DADA^&REV_00\5^&29635535^&0^&200048
echo Name: eyevis NPX-4800-DVI2-2
echo Driver is running.
echo 6 matching device(s) found.
exit /b
So theoretically all you should have to add is an appropriate shutdown command in the middle of the IF block where I currently have the echo and REMs. I provided a link to some OS-specific examples that should help.
When I ran the script to test it, both of the "problem lines" in your example were caught.

Code: Select all

C:\Users\Marc\Desktop>test
here is where you would shut down
here is where you would shut down
C:\Users\Marc\Desktop>
If there is some problem with matching more than once (issuing two shutdown commands in short succession) a simple flag could be added that triggers after the first match, and doesn't allow any additional matches, etc. Just let us know if it needs to be fancied up or if this is good enough.

Re: Please help - analize batch results and reboot if requir

Posted: 21 Apr 2014 23:58
by dphillips26
Thanks a lot Magialisk!

I'm going to set up a test machine now and will let you know how it goes.

Cheers,
Dave

Re: Please help - analize batch results and reboot if requir

Posted: 22 Apr 2014 10:04
by foxidrive
This is all you need:


Code: Select all

devcon status *VEN_DADA* |find "The device has the following problem: 37" >nul && echo reboot command here

Re: Please help - analize batch results and reboot if requir

Posted: 22 Apr 2014 22:27
by Magialisk
Ahh yes the conditional/ternary style execution. I never got into the 'xxx && yyy || zzz' style but it sure is a lot nicer than my quick and dirty approach :) I was expecting someone to come drop in a 1-2 liner to solve this. Thanks foxidrive.

Also, I was assuming that the number 37 might change from time to time, so my proposed find string just catches on the fact that there is a problem, vs. the specific problem #37. I don't know which is better for the OP, but I thought I'd point that out for his coming experiments.

Re: Please help - analize batch results and reboot if requir

Posted: 22 Apr 2014 22:59
by Squashman
Magialisk wrote:Also, I was assuming that the number 37 might change from time to time, so my proposed find string just catches on the fact that there is a problem, vs. the specific problem #37. I don't know which is better for the OP, but I thought I'd point that out for his coming experiments.

Pretty trivial. Easy enough to change in both of your code.

Re: Please help - analize batch results and reboot if requir

Posted: 27 Apr 2014 23:34
by dphillips26
Magialist,
I tried your code and it worked perfectly, thanks a lot!

Foxdrive,
Thanks for your input, I will give your code a try also

I've been scratching my head on this issue for the past 3 months so It means a lot to get an answer so quickly.

Thanks heaps!
Dave

Re: Please help - analize batch results and reboot if requir

Posted: 28 Apr 2014 23:17
by Magialisk
No problem Dave. For what it's worth Foxi's does the exact same thing as mine, just in a more compact and efficient manner. I spelled it out in a potentially more readable form, but there's really no difference in the end.

Well, that and the fact that I took an artistic liberty in assuming that the number 37 might change, and Foxidrive coded it exactly as you asked for, looking for the error #37 exactly. I just wanted to point that out again in case my code give you "false positives" down the road, you can fix it by adding the 37 back into the find string, as shown in Foxi's code.

Glad we could help!