1
00:00:00,200 --> 00:00:01,050
In this demonstration,

2
00:00:01,050 --> 00:00:01,883
we're going to walk through

3
00:00:01,883 --> 00:00:03,240
how to schedule tasks.

4
00:00:03,240 --> 00:00:04,380
We're going to perform this by

5
00:00:04,380 --> 00:00:05,700
two different methods.

6
00:00:05,700 --> 00:00:07,680
We're going to use the "at" command,

7
00:00:07,680 --> 00:00:11,130
which will execute a one-time function or command

8
00:00:11,130 --> 00:00:13,260
in the future one time.

9
00:00:13,260 --> 00:00:15,480
Then we're going to go over cron jobs,

10
00:00:15,480 --> 00:00:17,850
using the "crontab" command.

11
00:00:17,850 --> 00:00:19,860
Cron is when we want to schedule tasks

12
00:00:19,860 --> 00:00:22,170
so they occur repeatedly in the future.

13
00:00:22,170 --> 00:00:23,910
And this, we're going to schedule all of our

14
00:00:23,910 --> 00:00:28,200
mainest jobs to run automatically over and over again.

15
00:00:28,200 --> 00:00:30,810
So the first thing we want to check out is the "at" command,

16
00:00:30,810 --> 00:00:32,810
which I'm going to create a simple file.

17
00:00:36,330 --> 00:00:38,790
OK, so we're going to add this to our directory.

18
00:00:38,790 --> 00:00:39,960
Now we're going to run a test

19
00:00:39,960 --> 00:00:42,510
to execute in the future one time.

20
00:00:42,510 --> 00:00:44,910
And that's going to be: remove this touch file

21
00:00:44,910 --> 00:00:46,470
that we just created, file A.

22
00:00:46,470 --> 00:00:47,873
So let's make sure it's in there.

23
00:00:49,680 --> 00:00:50,763
OK, we see file A.

24
00:00:52,380 --> 00:00:53,463
About six down.

25
00:00:55,354 --> 00:00:56,675
Now we're going to run a command,

26
00:00:56,675 --> 00:00:59,220
and we want to execute two minutes from now.

27
00:00:59,220 --> 00:01:04,220
So we're going to do: "at now + 2 minutes".

28
00:01:05,108 --> 00:01:08,070
And the interacting prompt is going to pop up.

29
00:01:08,070 --> 00:01:10,320
And here, all we do is input the commands

30
00:01:10,320 --> 00:01:11,940
that we want to run.

31
00:01:11,940 --> 00:01:13,040
We're going to remove,

32
00:01:13,890 --> 00:01:14,723
force,

33
00:01:20,787 --> 00:01:21,620
and do Ctrl + D.

34
00:01:24,720 --> 00:01:25,920
OK

35
00:01:25,920 --> 00:01:28,830
Now we're going to look at the queue, "atq".

36
00:01:28,830 --> 00:01:30,120
Now we see a schedule

37
00:01:30,120 --> 00:01:31,983
to execute in the next two minutes.

38
00:01:33,540 --> 00:01:35,430
OK. Time has passed.

39
00:01:35,430 --> 00:01:37,380
Now let's check the queue.

40
00:01:37,380 --> 00:01:39,240
Alright, that's the first indication that

41
00:01:39,240 --> 00:01:41,070
the command went through.

42
00:01:41,070 --> 00:01:43,170
Now let's look through our list.

43
00:01:43,170 --> 00:01:46,500
I'm going to "grep" for the file A,

44
00:01:46,500 --> 00:01:48,480
just to be clear it's out there.

45
00:01:48,480 --> 00:01:49,313
Alright.

46
00:01:52,350 --> 00:01:53,820
Alright. We're going to see now that file A

47
00:01:53,820 --> 00:01:55,530
is no longer there.

48
00:01:55,530 --> 00:01:59,070
So again, we used the "at" to execute a function or command

49
00:01:59,070 --> 00:02:01,170
one time in the future.

50
00:02:01,170 --> 00:02:02,910
In this next scenario, we're going to go through

51
00:02:02,910 --> 00:02:05,460
and use the "crontab" command

52
00:02:05,460 --> 00:02:07,200
to schedule an email reminder

53
00:02:07,200 --> 00:02:09,509
at a specific time in the future.

54
00:02:09,509 --> 00:02:12,300
Now the way the cron command is broken up,

55
00:02:12,300 --> 00:02:14,970
once you're editing the actual file,

56
00:02:14,970 --> 00:02:17,550
the first five fields are just going to reference

57
00:02:17,550 --> 00:02:18,870
different time periods.

58
00:02:18,870 --> 00:02:21,180
So the first field is going to reference minutes.

59
00:02:21,180 --> 00:02:23,790
The second field is going to represent hours.

60
00:02:23,790 --> 00:02:25,920
Next is going to be the day of the month.

61
00:02:25,920 --> 00:02:27,507
Fourth is going to be the month.

62
00:02:27,507 --> 00:02:30,870
And the fifth field is going to represent a day of the week,

63
00:02:30,870 --> 00:02:32,970
if you're going to make it a repetitive task.

64
00:02:32,970 --> 00:02:35,520
For example: "1" would equal Monday,

65
00:02:35,520 --> 00:02:39,420
so that means every Monday on this time,

66
00:02:39,420 --> 00:02:40,740
or maybe even a future date.

67
00:02:40,740 --> 00:02:42,060
Typically we're just going to use the

68
00:02:42,060 --> 00:02:45,000
minutes, hours and day.

69
00:02:45,000 --> 00:02:46,920
Or if you want to do one specific day,

70
00:02:46,920 --> 00:02:47,760
you're going to use

71
00:02:47,760 --> 00:02:50,850
minutes, hours, day, and day of the month.

72
00:02:50,850 --> 00:02:52,740
In this example, we're just going to use

73
00:02:52,740 --> 00:02:54,750
a specific hour in the future.

74
00:02:54,750 --> 00:02:58,110
And if it doesn't have any day tied to it,

75
00:02:58,110 --> 00:03:00,390
it's assumed it's going to occur daily.

76
00:03:00,390 --> 00:03:03,480
So we're going to set an email to be sent to us

77
00:03:03,480 --> 00:03:05,100
every day at a certain time.

78
00:03:05,100 --> 00:03:06,363
So let's try that first.

79
00:03:08,196 --> 00:03:09,029
"sudo crontab"

80
00:03:12,180 --> 00:03:13,320
To the user.

81
00:03:13,320 --> 00:03:14,153
I'll use myself.

82
00:03:15,630 --> 00:03:16,713
And "e" means edit.

83
00:03:18,420 --> 00:03:19,710
Alright. So we're going to do this

84
00:03:19,710 --> 00:03:21,840
for five minutes in the future.

85
00:03:21,840 --> 00:03:22,680
Or, four minutes in the future.

86
00:03:22,680 --> 00:03:25,380
Let's make it 17:20, if we look at my clock.

87
00:03:25,380 --> 00:03:27,577
So we'll put "20" here for the minutes.

88
00:03:27,577 --> 00:03:29,220
"17".

89
00:03:29,220 --> 00:03:31,270
Everything has to be in a 24-hour format.

90
00:03:34,560 --> 00:03:35,817
We'll put "bin/echo".

91
00:03:38,458 --> 00:03:41,630
Let's do "Please fill in your time sheet."

92
00:03:47,310 --> 00:03:49,710
The last field is going to be

93
00:03:49,710 --> 00:03:52,290
a path to the command that you're trying to execute.

94
00:03:52,290 --> 00:03:53,123
So an example:

95
00:03:53,123 --> 00:03:55,590
we're trying to execute a simple "echo" command.

96
00:03:55,590 --> 00:03:57,940
And it's going to email this information to us.

97
00:03:59,310 --> 00:04:00,143
OK, click.

98
00:04:01,440 --> 00:04:02,340
Right click.

99
00:04:02,340 --> 00:04:03,173
Alright.

100
00:04:05,310 --> 00:04:07,410
Alright, let's check that mail really quick.

101
00:04:07,410 --> 00:04:08,883
OK, we see July 4th today.

102
00:04:13,380 --> 00:04:16,620
OK. We see that it was successfully received

103
00:04:16,620 --> 00:04:19,713
at 17:20 and one second.

104
00:04:21,510 --> 00:04:22,800
Alright, that sums that up.

105
00:04:22,800 --> 00:04:24,540
We went through how to use the "at" command

106
00:04:24,540 --> 00:04:26,790
for a future transaction.

107
00:04:26,790 --> 00:04:29,610
We also went over how to use a "crontab", edit that.

108
00:04:29,610 --> 00:04:31,710
We sent an email to ourself in the future.

109
00:04:31,710 --> 00:04:33,840
And right now it's set for a recurring task

110
00:04:33,840 --> 00:04:35,820
that happens once a day.

111
00:04:35,820 --> 00:04:37,170
Thank you for sticking with this walkthrough,

112
00:04:37,170 --> 00:04:38,970
and I'll see you in the next lesson.

