Advertisement

10.11.2008 at 10:05AM PDT, ID: 23806639 | Points: 500
[x]
Attachment Details

multiple if statements

Asked by directi in Windows Batch Scripting

Tags:

                            The below are multiple if statements but when i run it just the first one runs, i need all of them to run and also ONLY if all are true then the exit status should be 0 else status should be 1 and appropriate if statement which failed should be echo-ed.Also rather than cd into the program folder iw ould like to set the path and run these commands from the current directory.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
{code}
@echo off
set status=0
cd "C:\Program Files (x86)\MegaRAID Storage Manager"
MegaCli -? > nul
if not %errorlevel%==0 (
echo MegaRAID Storage Manager is not installed or not in path
exit 2
)
 
REM Check Vitual disk state
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Degraded"') do If "%%a" EQU "Degraded        : 0" SET status=0
if %status%==0 (
echo Raid is OK>1.txt
exit 0
)
if %status%==1 (
echo Raid is DeGraded
exit 1
}
 
REM Check for Offline Virtual disks
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Offline"') do If "%%a" EQU "Offline         : 0" SET status=0
if %status%==0 (
exit 0
)
if %status%==1 (
echo A drive went Offline
exit 1
)
 
REM Check for critical disk
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Critical Disks"') do If "%%a" EQU "Critical Disks  : 0" SET status=0
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo A disk is Critical
exit 1
)
 
REM Check for failed disk
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Failed Disks"') do If "%%a" EQU "Failed Disks    : 0" SET status=0
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo A disk has Failed
exit 1
 
REM Check for predictive failure of disk
)
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Predictive Filure Count"') do If "%%a" EQU "Predictive Failure Count: 0" SET status=0
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo Predictive Failure Count is Critical 
exit 1
)
 
REM Check for media errors on disk
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Media Error Count"') do If "%%a" EQU "Media Error Count: 0" SET status=0
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo Media Error Count is Critical 
exit 1
)
 
REM Check for other errors
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Other Error Count"') do If "%%a" EQU "Other Error Count: 0" SET status=0
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo Other Error Count is Critical 
exit 1
)
 
REM Check for issues with raidcard firmware
for /f "tokens=*" %%a in ('MegaCli -AdpAllInfo -a0 ^| find "Firmware state"') do If "%%a" EQU "Firmware state: Online" SET status=0
if %status%==0 (
echo Raid is OK
exit 0
)
if %status%==1 (
echo Firmware state is Critical 
exit 1
)
{code}
[+][-]10.12.2008 at 07:06AM PDT, ID: 22697425

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 08:31PM PDT, ID: 22708393

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628