Solved

batch script to look for exceptions

Posted on 2008-10-10
4
91 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 29

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 29

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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