Solved

batch script to look for exceptions

Posted on 2008-10-10
4
84 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now