Solved

batch script to look for exceptions

Posted on 2008-10-10
4
89 Views
Last Modified: 2014-11-20
Hello,

Below is the command  i run to check my raid status :


C:\Program Files\PowerEdge Diagnostics\oldiags\bin>pediags raidctrl --show all|f
ind "Device Status"
Device Status       : Device is working properly.
Device Status       : Device is working properly.
Device Status       : Device is working properly.
Device Status       : Device is working properly.
Device Status       : Device is working properly.


            I would like to create a script which would throw an error if any of the lines beginning with "Device Status" have any output other than  Device is working properly.Below is what i have so far:
@echo off
set status=0
cd C:\Program Files\PowerEdge Diagnostics\oldiags\bin
pediags -? > nul
if not %errorlevel%==0 (
echo Dell Poweredge Diagnostice is not installed or not in path
exit 2
)
cd C:\Program Files\PowerEdge Diagnostics\oldiags\bin
pediags raidctrl --show all |find "Device is working properly" >nul
if %errorlevel%==0 set status=0
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo Raid is DeGraded
exit 1
)

Open in new window

0
Comment
Question by:directi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Expert Comment

by:Michael Pfister
ID: 22685759
@echo off
set status=0
cd "C:\Program Files\PowerEdge Diagnostics\oldiags\bin"
pediags -? > nul
if not %errorlevel%==0 (
echo Dell Poweredge Diagnostice is not installed or not in path
exit 2
)
for /f "tokens=*" %%a in ('pediags raidctrl --show all ^| find "Device Status"') do If "%%a" NEQ "Device Status       : Device is working properly." SET status=1
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo Raid is DeGraded
exit 1
)
0
 
LVL 28

Accepted Solution

by:
Michael Pfister earned 125 total points
ID: 22685766
Sorry, wrong window
@echo off
set status=0
cd "C:\Program Files\PowerEdge Diagnostics\oldiags\bin"
pediags -? > nul
if not %errorlevel%==0 (
echo Dell Poweredge Diagnostice is not installed or not in path
exit 2
)
for /f "tokens=*" %%a in ('pediags raidctrl --show all ^| find "Device Status"') do If "%%a" NEQ "Device Status       : Device is working properly." SET status=1
 
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo Raid is DeGraded
exit 1
)

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question