1
00:00:00,000 --> 00:00:05,007
(upbeat instrumental music)

2
00:00:05,007 --> 00:00:06,005
- [Instructor] Let's look at

3
00:00:06,005 --> 00:00:08,007
solving those challenges

4
00:00:08,007 --> 00:00:10,006
having to do with the greatest number,

5
00:00:10,006 --> 00:00:11,008
and largest number

6
00:00:11,008 --> 00:00:14,008
or things related to loadable modules.

7
00:00:14,008 --> 00:00:16,001
So the first question is,

8
00:00:16,001 --> 00:00:19,000
the greatest number of used by.

9
00:00:19,000 --> 00:00:22,008
So we look at lsmod,

10
00:00:22,008 --> 00:00:24,008
and remember it's that last column,

11
00:00:24,008 --> 00:00:27,000
that's the used by,

12
00:00:27,000 --> 00:00:29,005
and we can see if there's more than one used by,

13
00:00:29,005 --> 00:00:31,005
there's a comma.

14
00:00:31,005 --> 00:00:34,000
So a little shell scripting,

15
00:00:34,000 --> 00:00:37,000
Trick, we're going to count commas

16
00:00:37,000 --> 00:00:38,007
if that's the only time there's going to be a comma,

17
00:00:38,007 --> 00:00:41,002
the output of lsmod.

18
00:00:41,002 --> 00:00:46,002
So I've got a little script.

19
00:00:46,002 --> 00:00:47,000
It's a little bit tricky,

20
00:00:47,000 --> 00:00:48,000
but I'll walk you through it quick.

21
00:00:48,000 --> 00:00:49,005
So we're going to run the lsmod command.

22
00:00:49,005 --> 00:00:52,000
We're going to pipe it into the while,

23
00:00:52,000 --> 00:00:54,002
and then everything we print in the while

24
00:00:54,002 --> 00:00:57,008
is going to get piped into sort numerically.

25
00:00:57,008 --> 00:01:02,000
So the last line will have the biggest number,

26
00:01:02,000 --> 00:01:05,002
and then we're going to read each line

27
00:01:05,002 --> 00:01:08,004
of output into a variable called line.

28
00:01:08,004 --> 00:01:11,002
We're going to echo that into a tricky set here,

29
00:01:11,002 --> 00:01:13,006
and that was the hint.

30
00:01:13,006 --> 00:01:16,001
So this expression right here with the hat,

31
00:01:16,001 --> 00:01:18,005
and the comma in square brackets

32
00:01:18,005 --> 00:01:20,002
means a character glass

33
00:01:20,002 --> 00:01:23,005
of all characters except for comma.

34
00:01:23,005 --> 00:01:25,002
And we're substituting all characters

35
00:01:25,002 --> 00:01:27,009
except for comma, for nothing

36
00:01:27,009 --> 00:01:28,009
across the whole line.

37
00:01:28,009 --> 00:01:30,000
That's the G there.

38
00:01:30,000 --> 00:01:32,003
So what that means is the only thing

39
00:01:32,003 --> 00:01:35,008
left on the line are going to be all the commas.

40
00:01:35,008 --> 00:01:37,004
And then we're going to count

41
00:01:37,004 --> 00:01:38,007
the number of characters left.

42
00:01:38,007 --> 00:01:40,006
That's the number of commas,

43
00:01:40,006 --> 00:01:41,005
and we're going to put that

44
00:01:41,005 --> 00:01:43,008
in a variable called commas.

45
00:01:43,008 --> 00:01:45,001
Then we're going to echo out

46
00:01:45,001 --> 00:01:47,006
the value of commas and then the line.

47
00:01:47,006 --> 00:01:50,004
So the first thing, output will be the number.

48
00:01:50,004 --> 00:01:51,008
And then when we sort the line,

49
00:01:51,008 --> 00:01:54,005
we'll be sorting by the number.

50
00:01:54,005 --> 00:02:02,007
So let's give that a try,

51
00:02:02,007 --> 00:02:03,007
and everything scrolls off.

52
00:02:03,007 --> 00:02:06,001
And then we look at the last line there,

53
00:02:06,001 --> 00:02:09,006
it says there's five used by for X tables,

54
00:02:09,006 --> 00:02:14,008
and it lists XT contract and T compact so forth.

55
00:02:14,008 --> 00:02:18,003
Looks like five of them there.

56
00:02:18,003 --> 00:02:20,004
The next question was,

57
00:02:20,004 --> 00:02:24,000
what's the largest use count?

58
00:02:24,000 --> 00:02:27,000
Perhaps having to do with

59
00:02:27,000 --> 00:02:29,002
the number of processes,

60
00:02:29,002 --> 00:02:30,009
say using a module.

61
00:02:30,009 --> 00:02:34,008
So remember lsmod,

62
00:02:34,008 --> 00:02:39,001
that number in the third column is the use count.

63
00:02:39,001 --> 00:02:42,001
So scsi_transport_iscsi is a 1,

64
00:02:42,001 --> 00:02:45,000
802 1q is a zero.

65
00:02:45,000 --> 00:02:47,007
LLC is a 2 and so forth.

66
00:02:47,007 --> 00:02:51,003
So I've got a script to help with that too.

67
00:02:51,003 --> 00:02:55,004
Largestcount.sh.

68
00:02:55,004 --> 00:02:57,003
So again, we're going to pipe lsmod

69
00:02:57,003 --> 00:02:59,004
into a while loop,

70
00:02:59,004 --> 00:03:02,001
and then we're going to use a hawk.

71
00:03:02,001 --> 00:03:03,002
It's a quick little hawk thing.

72
00:03:03,002 --> 00:03:07,002
This prints the third column, prints the number,

73
00:03:07,002 --> 00:03:10,005
and then we're going to echo out

74
00:03:10,005 --> 00:03:11,008
the number and the line.

75
00:03:11,008 --> 00:03:15,000
So again, the first thing will be a number,

76
00:03:15,000 --> 00:03:17,001
and we're going to sort numerically.

77
00:03:17,001 --> 00:03:21,000
So let's run that.

78
00:03:21,000 --> 00:03:23,008
And at the end there, we got 21.

79
00:03:23,008 --> 00:03:27,006
NF tables is in use.

80
00:03:27,006 --> 00:03:30,005
21 times.

81
00:03:30,005 --> 00:03:33,000
X tables only used five times, right.

82
00:03:33,000 --> 00:03:38,003
So big difference there.

83
00:03:38,003 --> 00:03:40,009
And then the last question was,

84
00:03:40,009 --> 00:03:43,001
number of dependencies.

85
00:03:43,001 --> 00:03:45,004
So that has to do with module dependencies.

86
00:03:45,004 --> 00:03:48,004
So let's go to lib/modules

87
00:03:48,004 --> 00:03:52,002
our kernel version directory.

88
00:03:52,002 --> 00:03:57,002
And remember, modules.dep

89
00:03:57,002 --> 00:03:59,000
has a line per module.

90
00:03:59,000 --> 00:04:01,005
It's got the path name for the module,

91
00:04:01,005 --> 00:04:02,009
then a colon,

92
00:04:02,009 --> 00:04:04,005
then a list of the dependencies

93
00:04:04,005 --> 00:04:07,008
separated by a space.

94
00:04:07,008 --> 00:04:10,009
So if we look at a script for that,

95
00:04:10,009 --> 00:04:14,005
back in my home directory,

96
00:04:14,005 --> 00:04:15,009
we're going to do another while,

97
00:04:15,009 --> 00:04:17,007
but instead of a command,

98
00:04:17,007 --> 00:04:22,002
we're going to read from a file.

99
00:04:22,002 --> 00:04:25,001
So we do a input redirection there.

100
00:04:25,001 --> 00:04:27,005
So again, we're going to have

101
00:04:27,005 --> 00:04:31,003
the variable line be each line in this file.

102
00:04:31,003 --> 00:04:32,008
We're going to echo that into another

103
00:04:32,008 --> 00:04:33,009
tricky little set here.

104
00:04:33,009 --> 00:04:36,000
This is not square bracket.

105
00:04:36,000 --> 00:04:39,003
So this hat here means beginning of the line.

106
00:04:39,003 --> 00:04:41,008
So we're going to go from

107
00:04:41,008 --> 00:04:43,007
the beginning of the line up to the colon,

108
00:04:43,007 --> 00:04:45,001
and get rid of everything.

109
00:04:45,001 --> 00:04:48,005
So that gets rid of like the path

110
00:04:48,005 --> 00:04:51,007
right to a module,

111
00:04:51,007 --> 00:04:53,008
the first part of the line up to the colon.

112
00:04:53,008 --> 00:04:56,008
And then what'll be left are the dependencies.

113
00:04:56,008 --> 00:04:58,006
And those are separated by a space,

114
00:04:58,006 --> 00:05:01,004
and there's no space in path names

115
00:05:01,004 --> 00:05:02,009
in Linux here.

116
00:05:02,009 --> 00:05:04,005
So if we count the number of words,

117
00:05:04,005 --> 00:05:07,008
that's like counting the number of those paths.

118
00:05:07,008 --> 00:05:10,007
So that'll be the number of dependencies.

119
00:05:10,007 --> 00:05:17,007
Let's give that a try.

120
00:05:17,007 --> 00:05:20,001
And they all come out sorted.

121
00:05:20,001 --> 00:05:23,003
But at the end here, the last one is 11.

122
00:05:23,003 --> 00:05:28,003
So this MLXSW spectrum

123
00:05:28,003 --> 00:05:31,005
depends on 11 modules that have to be loaded

124
00:05:31,005 --> 00:05:34,000
before you can load that one.

125
00:05:34,000 --> 00:05:34,008
All right.

126
00:05:34,008 --> 00:05:37,003
I hope that gives you a feel for dependencies,

127
00:05:37,003 --> 00:05:40,000
and a little bit of scripting challenge.

