1
00:00:00,000 --> 00:00:01,290
Being assistant administrator,

2
00:00:01,290 --> 00:00:03,540
you're going to have to do a lot of different tasks.

3
00:00:03,540 --> 00:00:04,590
So it's very important

4
00:00:04,590 --> 00:00:08,010
to be able to automate these tasks using scripts.

5
00:00:08,010 --> 00:00:10,050
So we're going to go through it in this walk through

6
00:00:10,050 --> 00:00:12,810
of how to customize first, our environment

7
00:00:12,810 --> 00:00:16,020
to make it productive for the scripts that we want to run.

8
00:00:16,020 --> 00:00:18,593
So the first command we'll use is environment command.

9
00:00:19,487 --> 00:00:21,150
This is going to give us a list of all the variables

10
00:00:21,150 --> 00:00:23,100
relative to our environment.

11
00:00:23,100 --> 00:00:25,110
The one we're going to focus on here

12
00:00:25,110 --> 00:00:27,213
is the history size, just for an example.

13
00:00:29,640 --> 00:00:30,690
Move towards the top.

14
00:00:31,680 --> 00:00:34,800
So you can see the history size is 1000,

15
00:00:34,800 --> 00:00:37,950
meaning that's going to store the last 1000 commands

16
00:00:37,950 --> 00:00:39,360
but we're going to change that.

17
00:00:39,360 --> 00:00:42,690
Now, another way to view variables,

18
00:00:42,690 --> 00:00:44,370
is just use the dollar sign.

19
00:00:44,370 --> 00:00:46,440
I'm going to use this command, echo.

20
00:00:46,440 --> 00:00:48,000
And it's going to tell us exactly

21
00:00:48,000 --> 00:00:50,850
what the value of that variable is

22
00:00:50,850 --> 00:00:54,453
because how the variables are set up are key value pairs.

23
00:00:55,500 --> 00:00:58,110
So the key is going to be histsize,

24
00:00:58,110 --> 00:01:01,053
the value is going to be 1000 and we're about to change that.

25
00:01:02,288 --> 00:01:03,363
We see the history.

26
00:01:05,489 --> 00:01:07,640
We see we have a lot of different commands.

27
00:01:08,520 --> 00:01:11,100
So in order to change the variable,

28
00:01:11,100 --> 00:01:13,203
we're going to use the export command.

29
00:01:16,024 --> 00:01:17,850
Now we're just going to use a low value

30
00:01:17,850 --> 00:01:19,983
just to make the demonstration easier.

31
00:01:21,360 --> 00:01:22,860
So just going to run a few commands.

32
00:01:22,860 --> 00:01:27,463
We're going to do echo one.

33
00:01:38,635 --> 00:01:40,823
All right, so if we scroll up with our arrow,

34
00:01:43,080 --> 00:01:45,120
we see we only stop at three,

35
00:01:45,120 --> 00:01:47,070
'cause clear is also a command, right?

36
00:01:47,070 --> 00:01:51,660
So, one, two, three, four, five.

37
00:01:51,660 --> 00:01:53,010
Can't go anymore than that.

38
00:01:53,010 --> 00:01:55,710
So test that out.

39
00:01:55,710 --> 00:01:57,690
So next thing we're going to do, we're going to make a directory

40
00:01:57,690 --> 00:01:59,140
to actually hold our scripts.

41
00:02:04,710 --> 00:02:06,060
Okay.

42
00:02:06,060 --> 00:02:09,000
And I have a script currently in my directory.

43
00:02:09,000 --> 00:02:11,693
We're going to move it to the scripts folder.

44
00:02:11,693 --> 00:02:12,690
Okay, going to do sudo,

45
00:02:12,690 --> 00:02:14,343
since it's in the root directory.

46
00:02:24,180 --> 00:02:25,480
Make sure they went there.

47
00:02:30,390 --> 00:02:32,730
Now, one thing that's important to note,

48
00:02:32,730 --> 00:02:35,250
we need to change the permissions on here

49
00:02:35,250 --> 00:02:37,353
if we're going to execute this script.

50
00:02:38,340 --> 00:02:40,403
So just going to do a change mod really quick.

51
00:02:49,380 --> 00:02:51,003
Going to do 775 right now.

52
00:02:52,020 --> 00:02:53,550
All right.

53
00:02:53,550 --> 00:02:55,320
Now, one thing we have to worry about

54
00:02:55,320 --> 00:02:58,290
when we're using scripts is the path variable.

55
00:02:58,290 --> 00:03:01,320
So the path variable lets the system know

56
00:03:01,320 --> 00:03:04,320
where are these commands located when you just type them up.

57
00:03:05,310 --> 00:03:10,310
So for example, when we type in just clear or last log,

58
00:03:10,890 --> 00:03:12,750
these commands are stored somewhere.

59
00:03:12,750 --> 00:03:14,670
And in order for the system to know where it's located,

60
00:03:14,670 --> 00:03:17,850
we must set that in our path variable.

61
00:03:17,850 --> 00:03:18,690
So first let's just see

62
00:03:18,690 --> 00:03:20,730
what our path variable looks like now.

63
00:03:20,730 --> 00:03:22,880
It's going to be a list of multiple variables.

64
00:03:24,540 --> 00:03:26,250
So these are all the possible locations

65
00:03:26,250 --> 00:03:30,480
that Linux will look to see how to execute that command.

66
00:03:30,480 --> 00:03:31,680
All right, now to change that for us,

67
00:03:31,680 --> 00:03:34,080
we're going to look at our bash profile command.

68
00:03:34,080 --> 00:03:36,633
So we're going to vim.

69
00:03:41,100 --> 00:03:43,200
All right, so we need to export this path.

70
00:03:48,600 --> 00:03:49,433
And we're going to make sure

71
00:03:49,433 --> 00:03:51,080
that we include the current variable.

72
00:03:52,590 --> 00:03:54,880
And then we're also going to add the scripts

73
00:03:56,550 --> 00:03:58,020
'cause that's where the script

74
00:03:58,020 --> 00:04:01,080
that we just moved to the scripts folder is located.

75
00:04:01,080 --> 00:04:02,190
So by the end of this,

76
00:04:02,190 --> 00:04:05,370
we're going to be able to type echo.sh

77
00:04:05,370 --> 00:04:07,530
and the system's going to know where to locate it

78
00:04:07,530 --> 00:04:08,880
and how to run it.

79
00:04:08,880 --> 00:04:13,710
Okay, now one thing we must do is use this source command

80
00:04:13,710 --> 00:04:17,490
and that's going to pretty much reload the bash.profile

81
00:04:17,490 --> 00:04:19,200
so the system knows to re-look

82
00:04:19,200 --> 00:04:21,300
at the new configuration file.

83
00:04:21,300 --> 00:04:24,217
Okay, now let's look at the path variable now.

84
00:04:26,320 --> 00:04:28,950
Okay, now we see what's added at the bottom.

85
00:04:28,950 --> 00:04:31,743
You see after the last colon, we see a /scripts.

86
00:04:32,730 --> 00:04:34,170
Now let's try that bad boy out.

87
00:04:34,170 --> 00:04:35,640
Do echo.sh.

88
00:04:35,640 --> 00:04:39,030
All right, well we see that went through successfully.

89
00:04:39,030 --> 00:04:42,480
Again, that script simply just prints out different lines

90
00:04:42,480 --> 00:04:44,133
just for the sake of the example.

91
00:04:45,390 --> 00:04:47,550
So if you want to check it out, see what it looks like,

92
00:04:47,550 --> 00:04:48,383
you just do cat.

93
00:04:51,935 --> 00:04:54,120
And you see that's how a script looks.

94
00:04:54,120 --> 00:04:55,770
And again, if you just look at the lines

95
00:04:55,770 --> 00:04:58,170
after the first one, where you see echo commands,

96
00:04:58,170 --> 00:04:59,340
just print out things

97
00:04:59,340 --> 00:05:00,810
and then see that the system will run it

98
00:05:00,810 --> 00:05:03,543
just by typing in the command without anything prior.

99
00:05:04,980 --> 00:05:07,920
Now the last one we'll go over is how to create an alias

100
00:05:07,920 --> 00:05:11,130
for a lengthy command that we typically use.

101
00:05:11,130 --> 00:05:14,730
So for example, I'm going to use this last log command

102
00:05:14,730 --> 00:05:18,210
which shows the last login for all the users.

103
00:05:18,210 --> 00:05:21,280
The tail, meaning that we're going to start

104
00:05:23,160 --> 00:05:24,250
with the second line

105
00:05:25,965 --> 00:05:27,480
and we're going to sort it

106
00:05:27,480 --> 00:05:29,480
by the first line in alphabetical order.

107
00:05:31,380 --> 00:05:32,213
Okay.

108
00:05:35,910 --> 00:05:37,710
Typically we have the header at the top,

109
00:05:37,710 --> 00:05:39,930
the username and the time,

110
00:05:39,930 --> 00:05:41,130
but we just want the information

111
00:05:41,130 --> 00:05:43,350
so that's why we started with line number two.

112
00:05:43,350 --> 00:05:44,670
And we see this in the alphabetical order

113
00:05:44,670 --> 00:05:46,563
based off the username or process.

114
00:05:50,160 --> 00:05:52,410
Now we don't want to have to type it all the time.

115
00:05:52,410 --> 00:05:56,253
So what we can do is run a change in our .bashrc file.

116
00:06:00,630 --> 00:06:02,160
If you look at the last section

117
00:06:02,160 --> 00:06:04,590
as user specific aliases and functions,

118
00:06:04,590 --> 00:06:06,023
that's where we're going to input that.

119
00:06:07,320 --> 00:06:08,223
Type in alias.

120
00:06:09,720 --> 00:06:10,680
Going to name it ulog.

121
00:06:13,830 --> 00:06:15,383
This where we're going to type in the command.

122
00:06:33,570 --> 00:06:35,470
Again, we must run our source command.

123
00:06:38,160 --> 00:06:40,650
All right, now we have reloaded that configuration

124
00:06:40,650 --> 00:06:41,750
and now let's type it.

125
00:06:43,290 --> 00:06:46,410
And you can see the alias ran the full command for us.

126
00:06:46,410 --> 00:06:47,670
So we just walked through a quick way

127
00:06:47,670 --> 00:06:49,470
of how to set up our shell environment

128
00:06:49,470 --> 00:06:51,810
to make scripts and alias for different commands

129
00:06:51,810 --> 00:06:53,520
to make it easier for us to run

130
00:06:53,520 --> 00:06:56,760
and make our jobs easier as system administrators.

131
00:06:56,760 --> 00:06:58,170
Thank you for sticking with this walkthrough

132
00:06:58,170 --> 00:06:59,970
and I'll see you in the next lesson.

