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
Solved

batch script to look for exceptions

Posted on 2008-10-10
4
88 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
  • 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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 …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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