1
00:00:00,000 --> 00:00:03,000
In this lesson, we'll go ahead and create a script.

2
00:00:03,000 --> 00:00:04,230
So we're just going to walk through some

3
00:00:04,230 --> 00:00:06,000
of the commands that's in the script

4
00:00:06,000 --> 00:00:08,160
and just go over how it's broken down

5
00:00:08,160 --> 00:00:09,630
and describe some of the commands

6
00:00:09,630 --> 00:00:11,880
that make it easier to understand.

7
00:00:11,880 --> 00:00:14,343
So the first thing we want to do we're going to create a file.

8
00:00:16,980 --> 00:00:18,690
Name it check_storage.

9
00:00:26,799 --> 00:00:28,410
Now we use a test command just to create

10
00:00:28,410 --> 00:00:29,710
a shell of that file

11
00:00:30,630 --> 00:00:31,980
and we're going to change the ownership.

12
00:00:31,980 --> 00:00:33,270
So we're able to modify it

13
00:00:33,270 --> 00:00:34,890
cause we're going to use a text editor.

14
00:00:34,890 --> 00:00:36,450
So we going to change the ownership to me

15
00:00:36,450 --> 00:00:37,830
cause it's right now it's under the root

16
00:00:37,830 --> 00:00:39,570
and then we'll be able to change it

17
00:00:39,570 --> 00:00:41,020
and make manipulations to it.

18
00:00:41,940 --> 00:00:43,203
We'll change own command.

19
00:00:46,830 --> 00:00:47,703
Change it to me.

20
00:00:53,790 --> 00:00:57,543
Okay. Then we have to change the permissions.

21
00:01:01,620 --> 00:01:02,460
All right.

22
00:01:02,460 --> 00:01:05,069
So let's make sure they went through.

23
00:01:05,069 --> 00:01:07,440
Okay. Now it's a lot easier to manipulate

24
00:01:07,440 --> 00:01:09,634
the scripts using that text editor

25
00:01:09,634 --> 00:01:11,634
so we going to applications, accessories

26
00:01:13,440 --> 00:01:14,283
to text editor.

27
00:01:16,770 --> 00:01:17,770
We're going to open it.

28
00:01:21,780 --> 00:01:22,920
Typically it's going to be

29
00:01:22,920 --> 00:01:24,280
in other locations

30
00:01:25,440 --> 00:01:26,910
computer

31
00:01:26,910 --> 00:01:27,743
scripts

32
00:01:29,700 --> 00:01:30,573
storage.

33
00:01:31,784 --> 00:01:33,320
Okay.

34
00:01:33,320 --> 00:01:35,433
Now we're going to modify this text editor.

35
00:01:36,450 --> 00:01:38,200
We want to display the line numbers

36
00:01:39,210 --> 00:01:41,700
and I like to highlight the current number.

37
00:01:41,700 --> 00:01:43,170
So we're going to begin the script

38
00:01:43,170 --> 00:01:44,118
by writing some contextual echo statements

39
00:01:44,118 --> 00:01:46,830
just to let us know

40
00:01:46,830 --> 00:01:50,070
and whoever runs the command what's going on at this point.

41
00:01:50,070 --> 00:01:52,440
So whenever the script first runs

42
00:01:52,440 --> 00:01:54,720
this will let us know by printing out this message

43
00:01:54,720 --> 00:01:57,603
on the screen saying beginning storage check.

44
00:01:58,665 --> 00:01:59,865
I want to put the date in.

45
00:02:03,420 --> 00:02:04,920
It's going to echo the date.

46
00:02:04,920 --> 00:02:06,120
It's going to use the,

47
00:02:06,120 --> 00:02:08,219
remember the dollar sign is for a variable

48
00:02:08,219 --> 00:02:09,769
and going to use the date command.

49
00:02:12,480 --> 00:02:13,380
Okay?

50
00:02:13,380 --> 00:02:15,900
So at this point, what the system's going to do is

51
00:02:15,900 --> 00:02:17,250
read date

52
00:02:17,250 --> 00:02:18,810
and then it's going to print out the actual date by

53
00:02:18,810 --> 00:02:21,150
running the command analytics environment.

54
00:02:21,150 --> 00:02:23,700
And next we just going to add some hyphens.

55
00:02:23,700 --> 00:02:25,500
Again, this isn't important

56
00:02:25,500 --> 00:02:26,940
this is just going to make the output a little bit

57
00:02:26,940 --> 00:02:28,203
more visually appeasing.

58
00:02:30,540 --> 00:02:31,440
Okay.

59
00:02:31,440 --> 00:02:33,900
So next we're going to declare a variable.

60
00:02:33,900 --> 00:02:36,580
We will name it part, sample partition

61
00:02:37,620 --> 00:02:38,470
do a dev

62
00:02:39,540 --> 00:02:40,373
sda1

63
00:02:42,385 --> 00:02:45,480
Okay. Now we're about to run a command

64
00:02:45,480 --> 00:02:47,040
and we're going to declare this command.

65
00:02:47,040 --> 00:02:48,930
Of course it's going to be ours.

66
00:02:48,930 --> 00:02:52,140
Call it, check percentage.

67
00:02:52,140 --> 00:02:54,000
This command is about to get pretty lengthy

68
00:02:54,000 --> 00:02:56,450
but after I finish it, we're going to break it down.

69
00:03:07,020 --> 00:03:07,853
All right.

70
00:03:07,853 --> 00:03:09,000
So that's a pretty long command

71
00:03:09,000 --> 00:03:11,190
but what I'm going to do is I'm going to go back to the

72
00:03:11,190 --> 00:03:13,260
terminal and we're just going to break down each one

73
00:03:13,260 --> 00:03:14,400
just for a little reference.

74
00:03:14,400 --> 00:03:16,650
We should be familiar with all these at this point

75
00:03:16,650 --> 00:03:19,230
but again, for reference, we going to break it down.

76
00:03:19,230 --> 00:03:21,210
So first thing I'm going to go through is the

77
00:03:21,210 --> 00:03:22,870
disk free H

78
00:03:25,440 --> 00:03:29,310
so this command just shows us the storage that's available

79
00:03:29,310 --> 00:03:30,900
and it's going to put in a human readable format.

80
00:03:30,900 --> 00:03:33,120
That's what the H option stands for.

81
00:03:33,120 --> 00:03:33,953
Okay.

82
00:03:36,570 --> 00:03:37,670
Then we'll go to grip.

83
00:03:39,330 --> 00:03:40,380
Now we'll have to use grip

84
00:03:40,380 --> 00:03:42,750
and it's going to reference the variable that we said earlier

85
00:03:42,750 --> 00:03:46,170
but in our Linux environment, it doesn't recognize part.

86
00:03:46,170 --> 00:03:49,863
So we're going to have to actually type out the dev sda1.

87
00:03:59,970 --> 00:04:01,350
Okay.

88
00:04:01,350 --> 00:04:02,460
So what we see is just going to

89
00:04:02,460 --> 00:04:05,890
select the specific partition that we're looking for

90
00:04:06,810 --> 00:04:09,240
next going to add the awk command

91
00:04:09,240 --> 00:04:10,800
and remember that extracts the data

92
00:04:10,800 --> 00:04:13,860
in the fifth column from the results.

93
00:04:13,860 --> 00:04:15,760
So, let's check that out really quick.

94
00:04:21,390 --> 00:04:22,590
Okay. Since we have it up there

95
00:04:22,590 --> 00:04:25,020
it's easier to see the fifth columns going to be percentages.

96
00:04:25,020 --> 00:04:27,100
So it's just going to only take that value

97
00:04:29,010 --> 00:04:30,450
and next we going to use the cut command

98
00:04:30,450 --> 00:04:32,910
and we're going to reference the percent side

99
00:04:32,910 --> 00:04:34,170
and we're going to just remove it.

100
00:04:34,170 --> 00:04:36,960
So we're able to manipulate that variable only

101
00:04:36,960 --> 00:04:37,860
with the number itself.

102
00:04:37,860 --> 00:04:40,060
So the percentage side won't get in the way.

103
00:04:42,270 --> 00:04:43,533
So it's going to be cut.

104
00:04:52,830 --> 00:04:53,663
All right.

105
00:04:53,663 --> 00:04:55,710
So now we only pull the number

106
00:04:55,710 --> 00:04:57,540
from the, disk free command

107
00:04:57,540 --> 00:05:02,370
specific to the dev sda1 partition

108
00:05:02,370 --> 00:05:05,700
from the fifth column, which is the percentage

109
00:05:05,700 --> 00:05:07,650
and we're going to remove the percent sign

110
00:05:09,150 --> 00:05:10,450
and that's going to echo

111
00:05:11,460 --> 00:05:14,283
partition was going to reference dev sda1.

112
00:05:21,308 --> 00:05:26,308
We're going to reference the command that we just created.

113
00:05:26,460 --> 00:05:27,660
Add the percentage sign.

114
00:05:32,670 --> 00:05:33,503
Okay.

115
00:05:33,503 --> 00:05:35,580
So we'll see this command is just letting us know that

116
00:05:35,580 --> 00:05:37,770
we're going to spit out to the screen

117
00:05:37,770 --> 00:05:39,840
or a document

118
00:05:39,840 --> 00:05:43,860
that the partition dev sda1

119
00:05:43,860 --> 00:05:44,693
is

120
00:05:44,693 --> 00:05:46,860
and we going to run that command that we just went through

121
00:05:46,860 --> 00:05:48,360
add a percent sign to that value,

122
00:05:48,360 --> 00:05:50,520
which should be 25 full.

123
00:05:50,520 --> 00:05:52,890
So 25% full.

124
00:05:52,890 --> 00:05:54,900
Dune's going to let everyone know who's using this

125
00:05:54,900 --> 00:05:56,300
that the script is complete.

126
00:05:57,480 --> 00:05:58,313
Click save.

127
00:05:59,310 --> 00:06:00,960
I should better run this bad boy.

128
00:06:06,180 --> 00:06:07,140
Okay.

129
00:06:07,140 --> 00:06:09,210
So it went through successfully.

130
00:06:09,210 --> 00:06:11,700
It printed out everything that we put inside

131
00:06:11,700 --> 00:06:13,020
of our check storage

132
00:06:13,020 --> 00:06:16,620
that sh, echo beginning storage

133
00:06:16,620 --> 00:06:20,820
echo the date, echo the device, the percent full.

134
00:06:20,820 --> 00:06:21,930
We going to let the user know that

135
00:06:21,930 --> 00:06:23,630
the storage check is now complete.

136
00:06:25,080 --> 00:06:27,930
So now we're going to modify this script

137
00:06:27,930 --> 00:06:29,100
and we are just going to

138
00:06:29,100 --> 00:06:31,230
now redirect the information

139
00:06:31,230 --> 00:06:32,253
to a file.

140
00:06:33,630 --> 00:06:34,500
So this is a command,

141
00:06:34,500 --> 00:06:35,340
that's exactly what it does.

142
00:06:35,340 --> 00:06:36,930
It's the same telling us,

143
00:06:36,930 --> 00:06:38,250
hey, from this point on

144
00:06:38,250 --> 00:06:41,850
we're going to send everything into your home directory,

145
00:06:41,850 --> 00:06:43,750
under a file called storage_report.txt

146
00:06:47,730 --> 00:06:49,410
So let's also modify this last statement

147
00:06:49,410 --> 00:06:51,023
to let the user know that as well.

148
00:07:02,070 --> 00:07:03,370
Now last thing we must do,

149
00:07:04,691 --> 00:07:06,441
we going to add this piece right here.

150
00:07:07,350 --> 00:07:09,300
And that's going to let the system know

151
00:07:09,300 --> 00:07:13,950
that we going to send that last echo to the screen.

152
00:07:13,950 --> 00:07:15,930
Because it doesn't really need to be part of report.

153
00:07:15,930 --> 00:07:17,580
That's to let the person know,

154
00:07:17,580 --> 00:07:18,900
that is running the command

155
00:07:18,900 --> 00:07:21,390
where the information will be stored.

156
00:07:21,390 --> 00:07:22,530
Okay.

157
00:07:22,530 --> 00:07:23,583
Now let's save this.

158
00:07:25,200 --> 00:07:27,900
Now let's run that command one more time.

159
00:07:27,900 --> 00:07:29,248
Okay.

160
00:07:29,248 --> 00:07:30,081
So we see it went through.

161
00:07:30,081 --> 00:07:32,550
It's letting us know that it saved to the storage report

162
00:07:32,550 --> 00:07:33,650
For those of you yeah.

163
00:07:35,760 --> 00:07:36,600
Okay.

164
00:07:36,600 --> 00:07:39,210
Looks like it went through successfully.

165
00:07:39,210 --> 00:07:40,043
Okay.

166
00:07:40,043 --> 00:07:41,310
We just walked through the basics of creating

167
00:07:41,310 --> 00:07:44,520
a small script of how to redirect the information to

168
00:07:44,520 --> 00:07:45,540
your report file

169
00:07:45,540 --> 00:07:47,130
or just keeping it on a screen

170
00:07:47,130 --> 00:07:49,110
for the user to see the information,

171
00:07:49,110 --> 00:07:50,760
and see the steps it's going through.

172
00:07:50,760 --> 00:07:53,820
But remember the script does what you tell it to do.

173
00:07:53,820 --> 00:07:56,040
So if you want to let the user know

174
00:07:56,040 --> 00:07:57,450
every step that's going through,

175
00:07:57,450 --> 00:08:00,390
that will be very helpful for whoever's using it.

176
00:08:00,390 --> 00:08:01,710
Thank you for sticking with this walkthrough.

177
00:08:01,710 --> 00:08:03,610
And I will see you in the next lesson.

