1
00:00:00,360 --> 00:00:02,336
In this demonstration,

2
00:00:02,336 --> 00:00:04,380
we're going to return to the check storage script,

3
00:00:04,380 --> 00:00:06,630
and we're going to go over a few things.

4
00:00:06,630 --> 00:00:07,770
Instead of me typing everything out,

5
00:00:07,770 --> 00:00:09,390
I just went ahead and typed it for us.

6
00:00:09,390 --> 00:00:10,980
But we're just going to go over

7
00:00:10,980 --> 00:00:14,727
conditional branches for an if else statement.

8
00:00:14,727 --> 00:00:16,563
Again, we want the script to be able

9
00:00:16,563 --> 00:00:18,122
to present information based

10
00:00:18,122 --> 00:00:21,114
off certain conditions of the system.

11
00:00:21,114 --> 00:00:22,472
So if we look here, I'll scroll

12
00:00:22,472 --> 00:00:24,660
down just a little bit to get to the part

13
00:00:24,660 --> 00:00:26,190
that I added.

14
00:00:26,190 --> 00:00:28,114
Now, if you look at line 13,

15
00:00:28,114 --> 00:00:31,399
I added our first conditional branch.

16
00:00:31,399 --> 00:00:33,607
What that statement is merely saying is,

17
00:00:33,607 --> 00:00:36,147
if we run the check per variable,

18
00:00:36,147 --> 00:00:37,740
that run earlier,

19
00:00:37,740 --> 00:00:40,103
that's the command that we created.

20
00:00:40,103 --> 00:00:42,621
If the value is greater than 95

21
00:00:42,621 --> 00:00:44,991
but less than 100% full,

22
00:00:44,991 --> 00:00:48,265
we want to print the echo statement alert.

23
00:00:48,265 --> 00:00:49,621
This partition,

24
00:00:49,621 --> 00:00:54,621
which is going to be /dev/sda1, is 25%.

25
00:00:54,750 --> 00:00:58,281
that's what it was in the last lesson, full

26
00:00:58,281 --> 00:01:01,023
and we recommend immediate action.

27
00:01:02,594 --> 00:01:05,099
But just think about that though.

28
00:01:05,099 --> 00:01:06,480
The fact that it's currently

29
00:01:06,480 --> 00:01:09,122
at 25% means that this wouldn't be triggered.

30
00:01:09,122 --> 00:01:11,381
So the value of that number has to

31
00:01:11,381 --> 00:01:12,506
actually be greater

32
00:01:12,506 --> 00:01:15,867
than 95

33
00:01:15,867 --> 00:01:17,691
in less than 100.

34
00:01:17,691 --> 00:01:20,640
So if it's 95, it won't pass the test.

35
00:01:20,640 --> 00:01:22,593
So anything 95 and below,

36
00:01:23,460 --> 00:01:26,764
this alert will not be triggered, but anything 96

37
00:01:26,764 --> 00:01:30,834
and above will be, long as it's less than 100.

38
00:01:30,834 --> 00:01:33,115
So again, it's going to go through

39
00:01:33,115 --> 00:01:36,330
each and every one of these conditional statements,

40
00:01:36,330 --> 00:01:37,758
and it's going to check if,

41
00:01:37,758 --> 00:01:38,923
then it's going to run the variable,

42
00:01:38,923 --> 00:01:41,268
it's going to run the command,

43
00:01:41,268 --> 00:01:43,590
and it's going to compare those values.

44
00:01:43,590 --> 00:01:45,180
And if the statement is true

45
00:01:45,180 --> 00:01:47,970
'cause remember both of the statements have to be true.

46
00:01:47,970 --> 00:01:49,924
It has to be greater than 95,

47
00:01:49,924 --> 00:01:52,419
but also less than 100.

48
00:01:52,419 --> 00:01:55,530
And then again, it's going to go through the next one.

49
00:01:55,530 --> 00:01:56,363
Else if.

50
00:01:56,363 --> 00:01:58,140
Next thing it's going to do, it's going to check to see

51
00:01:58,140 --> 00:02:02,454
if it's greater than 50, but less than 95.

52
00:02:02,454 --> 00:02:05,079
And it's going to print out a different command.

53
00:02:05,079 --> 00:02:06,446
It's going to print out caution,

54
00:02:06,446 --> 00:02:08,869
consider freeing up some space.

55
00:02:08,869 --> 00:02:11,350
Again, this is a more practical script

56
00:02:11,350 --> 00:02:12,753
because it gives us advice

57
00:02:12,753 --> 00:02:15,303
on what to do when certain conditions are met.

58
00:02:16,230 --> 00:02:17,760
So again, it's going to check to see

59
00:02:17,760 --> 00:02:19,461
if the particular partition is greater

60
00:02:19,461 --> 00:02:23,053
than 50 and also less than 95.

61
00:02:23,053 --> 00:02:25,968
The next FL statement, it's going to check to see

62
00:02:25,968 --> 00:02:29,160
if the partition is less than 50%.

63
00:02:29,160 --> 00:02:30,990
And if it is we're going to print out,

64
00:02:30,990 --> 00:02:32,820
hey, no action is needed

65
00:02:32,820 --> 00:02:35,130
because we determined anything less than 50%

66
00:02:35,130 --> 00:02:35,973
is good to go.

67
00:02:37,110 --> 00:02:38,824
Now, if it goes through this entire set

68
00:02:38,824 --> 00:02:40,584
of conditional branches and none

69
00:02:40,584 --> 00:02:42,916
of the conditions are met,

70
00:02:42,916 --> 00:02:44,310
we're going to print out that

71
00:02:44,310 --> 00:02:46,230
we encountered an error because it has

72
00:02:46,230 --> 00:02:47,805
to meet at least one of them.

73
00:02:47,805 --> 00:02:50,040
If not, then there's an issue.

74
00:02:50,040 --> 00:02:52,209
Remember that the >&2 if we

75
00:02:52,209 --> 00:02:54,470
have those together, that means that

76
00:02:54,470 --> 00:02:56,190
we're going to print that information

77
00:02:56,190 --> 00:02:59,010
out on the terminal for the user to read.

78
00:02:59,010 --> 00:03:00,270
And it's going to print out an error

79
00:03:00,270 --> 00:03:01,920
and it's going to give us its status code

80
00:03:01,920 --> 00:03:04,570
because that's what that particular variable,

81
00:03:04,570 --> 00:03:06,150
the question mark refers to.

82
00:03:06,150 --> 00:03:08,370
And then we're going to exit out.

83
00:03:08,370 --> 00:03:10,547
And the fi just means we're finished with that set

84
00:03:10,547 --> 00:03:12,570
of conditional statements that started

85
00:03:12,570 --> 00:03:14,032
with the if.

86
00:03:14,032 --> 00:03:16,270
Now let's go ahead and run that command

87
00:03:17,508 --> 00:03:18,933
and check storage.

88
00:03:23,153 --> 00:03:24,573
Now let's view this report.

89
00:03:27,657 --> 00:03:30,133
Now we see this time rather than just give us

90
00:03:30,133 --> 00:03:31,792
the information, we're also giving

91
00:03:31,792 --> 00:03:34,743
us the required action necessary.

92
00:03:35,744 --> 00:03:38,216
It's at 25% and no action is needed,

93
00:03:38,216 --> 00:03:40,563
because if you refer back to our script,

94
00:03:43,470 --> 00:03:46,039
anything that's less than 50 that's

95
00:03:46,039 --> 00:03:48,486
what's going to be executed.

96
00:03:48,486 --> 00:03:50,640
Next we're going to go through and actually modify

97
00:03:50,640 --> 00:03:54,210
this script to incorporate more than one drive

98
00:03:54,210 --> 00:03:56,790
because realistically we want to know the value

99
00:03:56,790 --> 00:03:58,800
of multiple sets of drives

100
00:03:58,800 --> 00:04:01,590
usually all versus just one.

101
00:04:01,590 --> 00:04:04,140
So we're going to modify this script

102
00:04:04,140 --> 00:04:04,973
to use everything

103
00:04:04,973 --> 00:04:07,560
that's associated in the /dev directory,

104
00:04:07,560 --> 00:04:09,090
which points to the hard disk

105
00:04:09,090 --> 00:04:11,518
that's associated to our system.

106
00:04:11,518 --> 00:04:14,100
So what we need to do is modify this partition

107
00:04:14,100 --> 00:04:15,641
variable that we established earlier.

108
00:04:15,641 --> 00:04:17,898
So we're going to make this into a command

109
00:04:17,898 --> 00:04:20,100
and this command is going to go through

110
00:04:20,100 --> 00:04:21,760
and it's going to check our /dev folder

111
00:04:21,760 --> 00:04:25,112
and everything that has the /dev associated

112
00:04:25,112 --> 00:04:29,253
with it. That's where we're going to reference.

113
00:04:29,253 --> 00:04:30,720
Let's do that really quick.

114
00:04:30,720 --> 00:04:32,640
So we're going to use the variable.

115
00:04:32,640 --> 00:04:34,950
So that means that we're going to get that information.

116
00:04:34,950 --> 00:04:36,690
Whatever the value that is returned,

117
00:04:36,690 --> 00:04:38,610
that's what we want to print out.

118
00:04:38,610 --> 00:04:41,220
Okay? So we know what that command means.

119
00:04:41,220 --> 00:04:43,570
We're going to take

120
00:04:46,738 --> 00:04:48,940
everything from the first row

121
00:04:54,795 --> 00:04:59,440
And it has to look like this /dev

122
00:05:02,370 --> 00:05:04,443
and that's going to be what's returned to us.

123
00:05:04,443 --> 00:05:07,740
So if we just use this command really quick

124
00:05:07,740 --> 00:05:10,830
in our shell, we'll see what we return to us.

125
00:05:10,830 --> 00:05:12,872
So again, we use a disk free human

126
00:05:12,872 --> 00:05:14,844
readable variable.

127
00:05:14,844 --> 00:05:16,866
We're going to pull out everything that's

128
00:05:16,866 --> 00:05:18,993
in the first row,

129
00:05:28,190 --> 00:05:32,773
and it must be presented in the /dev format.

130
00:05:34,300 --> 00:05:36,720
Okay? So once we run the script

131
00:05:36,720 --> 00:05:39,480
we should get the values for those two hard disks.

132
00:05:39,480 --> 00:05:40,680
'Cause that's what I have associated

133
00:05:40,680 --> 00:05:42,660
under /dev in this particular device.

134
00:05:42,660 --> 00:05:44,430
So we should get more than one value.

135
00:05:44,430 --> 00:05:47,202
We should also include the map or CentOS root.

136
00:05:47,202 --> 00:05:50,029
Okay? So now we know what that command means.

137
00:05:50,029 --> 00:05:52,200
Now, we need to do a loop.

138
00:05:52,200 --> 00:05:54,806
We need to actually check the first one

139
00:05:54,806 --> 00:05:57,090
the second one, third, etc.

140
00:05:57,090 --> 00:05:59,100
For this example, we only have two

141
00:05:59,100 --> 00:06:00,600
but we're going to modify this

142
00:06:00,600 --> 00:06:02,150
so that it's going to check multiple.

143
00:06:02,150 --> 00:06:04,141
And then it's going to convert that value

144
00:06:04,141 --> 00:06:06,080
that's returned in the partition variable

145
00:06:06,080 --> 00:06:07,957
into an array.

146
00:06:07,957 --> 00:06:10,110
And an array is nothing more

147
00:06:10,110 --> 00:06:13,384
than a set of similar values typically.

148
00:06:13,384 --> 00:06:15,240
And for this example

149
00:06:15,240 --> 00:06:17,670
the similar values are going to be the hard drives.

150
00:06:17,670 --> 00:06:18,960
So we're going to go through

151
00:06:18,960 --> 00:06:22,057
and loop through two different hard drives.

152
00:06:22,057 --> 00:06:23,973
Okay, let's go ahead and modify this.

153
00:06:25,096 --> 00:06:26,733
For this one do the four loop.

154
00:06:29,951 --> 00:06:33,119
The i represents the individual array that's

155
00:06:33,119 --> 00:06:36,273
selected once we're going through processing

156
00:06:36,273 --> 00:06:38,561
each one of these commands.

157
00:06:38,561 --> 00:06:40,030
We're going to do N

158
00:06:42,690 --> 00:06:43,523
partition.

159
00:06:44,760 --> 00:06:47,144
And this means all, every single one of them

160
00:06:47,144 --> 00:06:49,800
that's what the asterisk stands for.

161
00:06:49,800 --> 00:06:50,633
Okay?

162
00:06:53,812 --> 00:06:56,190
This is going to begin the four loop.

163
00:06:56,190 --> 00:06:58,838
And again, the i variable is the iterator.

164
00:06:58,838 --> 00:07:01,473
The part variable is being referenced

165
00:07:01,473 --> 00:07:03,957
as an array with the asterisk, indicating all values

166
00:07:03,957 --> 00:07:05,910
in that array.

167
00:07:05,910 --> 00:07:08,160
For every index in the array,

168
00:07:08,160 --> 00:07:10,803
the script will execute what follows after.

169
00:07:13,500 --> 00:07:17,380
Okay? So for that, we want to use the DO.

170
00:07:17,380 --> 00:07:19,770
And the DO statement begins the code

171
00:07:19,770 --> 00:07:23,849
that the loop will execute on each iteration.

172
00:07:23,849 --> 00:07:27,083
The i is going to represent /dev map or CentOS root

173
00:07:27,083 --> 00:07:30,626
and also /dev/sda1.

174
00:07:30,626 --> 00:07:32,340
Now let's go ahead and go to the bottom

175
00:07:32,340 --> 00:07:34,020
after the finish.

176
00:07:34,020 --> 00:07:35,220
Everyone type done.

177
00:07:35,220 --> 00:07:38,438
That's going to indicate the end of that loop.

178
00:07:38,438 --> 00:07:39,623
So before we continue,

179
00:07:39,623 --> 00:07:42,241
we have to modify every instance of

180
00:07:42,241 --> 00:07:45,010
the partition variable.

181
00:07:45,010 --> 00:07:48,043
Remember having return it to the i okay.

182
00:07:48,043 --> 00:07:48,963
A partition here.

183
00:07:51,864 --> 00:07:54,063
Need to reference that index,

184
00:07:55,351 --> 00:07:57,033
not the entire array.

185
00:08:11,130 --> 00:08:12,540
Okay.

186
00:08:12,540 --> 00:08:14,733
Make sure there's no more associations

187
00:08:14,733 --> 00:08:16,586
with the partition itself, but the index

188
00:08:16,586 --> 00:08:21,063
of that partition looks like we're good to go.

189
00:08:21,930 --> 00:08:22,897
Save.

190
00:08:22,897 --> 00:08:24,210
Alright.

191
00:08:24,210 --> 00:08:26,260
Now let's go ahead and rerun this command

192
00:08:28,530 --> 00:08:29,530
and see what we get.

193
00:08:32,730 --> 00:08:33,563
Okay.

194
00:08:37,400 --> 00:08:38,433
Perfect.

195
00:08:40,020 --> 00:08:41,159
Looks like we went through.

196
00:08:41,159 --> 00:08:43,110
We checked to see the information

197
00:08:43,110 --> 00:08:45,819
and the CentOS root is over 95% full

198
00:08:45,819 --> 00:08:48,660
so it requires immediate action.

199
00:08:48,660 --> 00:08:51,990
For the sda1 is only 25% full

200
00:08:51,990 --> 00:08:53,673
so no action is needed.

201
00:08:54,990 --> 00:08:57,180
Okay. We see that when it checked

202
00:08:57,180 --> 00:08:59,010
multiple different hard disks,

203
00:08:59,010 --> 00:09:00,240
that we were able to trigger different

204
00:09:00,240 --> 00:09:01,560
conditional branches.

205
00:09:01,560 --> 00:09:03,327
So we see that the CentOS root,

206
00:09:03,327 --> 00:09:04,726
was above 95% so it gave us

207
00:09:04,726 --> 00:09:08,700
the indication that immediate action was required.

208
00:09:08,700 --> 00:09:12,303
And we see that our sda1 was still good to go

209
00:09:12,303 --> 00:09:15,870
with less than 50% so no action was required.

210
00:09:15,870 --> 00:09:16,703
So just a recap.

211
00:09:16,703 --> 00:09:19,392
We went over how to create a script and modify it

212
00:09:19,392 --> 00:09:21,930
so it's able to iterate through

213
00:09:21,930 --> 00:09:22,763
multiple different

214
00:09:22,763 --> 00:09:25,735
hard disks to give us more practical information

215
00:09:25,735 --> 00:09:27,579
for managing our systems.

216
00:09:27,579 --> 00:09:29,520
Thank you for sticking with this walkthrough

217
00:09:29,520 --> 00:09:31,320
and I'll see you in the next lesson.

