1 00:00:00,000 --> 00:00:03,000 [No audio] 2 00:00:03,030 --> 00:00:06,450 Hi everyone. In our previous lecture, we 3 00:00:06,450 --> 00:00:09,570 have learned how we could schedule jobs 4 00:00:09,570 --> 00:00:13,620 or tasks to cronjob or addjob. And as we 5 00:00:13,620 --> 00:00:16,320 all know, that addjob is used for ad hoc 6 00:00:16,590 --> 00:00:20,220 task for one time use. And if you want 7 00:00:20,220 --> 00:00:23,880 to schedule jobs or specially repetitive 8 00:00:23,880 --> 00:00:26,918 job, you would use cronjob or crontab. 9 00:00:26,918 --> 00:00:29,280 Now, I want to cover some 10 00:00:29,310 --> 00:00:33,240 additional things about cronjob. By 11 00:00:33,240 --> 00:00:35,790 default, there are four different types 12 00:00:35,790 --> 00:00:39,480 of cronjob, that is set for you, that is 13 00:00:39,480 --> 00:00:41,940 like out of the box, that operating 14 00:00:41,940 --> 00:00:44,160 system the Linux operating system offers 15 00:00:44,160 --> 00:00:48,750 you, and those jobs are hourly job, daily 16 00:00:48,750 --> 00:00:54,570 jobs, weekly, and monthly. So anything, 17 00:00:55,800 --> 00:00:59,340 any task that you want to run hourly 18 00:00:59,340 --> 00:01:02,670 basis, or weekly, or monthly basis, you 19 00:01:02,670 --> 00:01:05,459 could do it two ways. One, you could do 20 00:01:05,489 --> 00:01:08,310 through the crontab minus e, and 21 00:01:08,310 --> 00:01:10,650 specify it over there. Or you could 22 00:01:10,650 --> 00:01:14,940 simply have the script added inside of 23 00:01:14,940 --> 00:01:17,070 the hourly, daily, weekly, monthly 24 00:01:17,100 --> 00:01:23,206 directories. Those directories are in /etc/cron., 25 00:01:23,206 --> 00:01:25,680 hourly, dot daily, weekly 26 00:01:25,710 --> 00:01:28,680 or monthly. So you go into each of these 27 00:01:28,680 --> 00:01:33,690 directories, and you put in your script 28 00:01:33,720 --> 00:01:37,290 that will run every hour, or depending 29 00:01:37,290 --> 00:01:39,720 on how often do you want to run. And 30 00:01:39,720 --> 00:01:41,520 then you don't have to do anything about 31 00:01:41,520 --> 00:01:43,920 the crontab or anything. Then the cron 32 00:01:43,920 --> 00:01:45,750 dot daily or hourly depending on which 33 00:01:45,750 --> 00:01:49,590 one you pick will do the job. Now the 34 00:01:49,590 --> 00:01:55,543 timing of each are set in /etc/anacrontab 35 00:01:55,543 --> 00:01:58,260 When you do cat, you will see 36 00:01:58,260 --> 00:02:01,560 that anacrontab has the timing of 37 00:02:01,560 --> 00:02:05,010 when the daily, weekly, and monthly job 38 00:02:05,010 --> 00:02:08,340 will run, except the hourly one. The 39 00:02:08,370 --> 00:02:12,300 hourly one is defined, the what time it 40 00:02:12,300 --> 00:02:18,078 runs it is defined in /etc/cron.d/0hourly. 41 00:02:18,078 --> 00:02:19,770 That's the file that 42 00:02:19,770 --> 00:02:23,400 defines when the hourly runs. So let me 43 00:02:23,400 --> 00:02:26,310 get into my Linux machine, and we'll see 44 00:02:26,310 --> 00:02:30,030 how these jobs are set up in each 45 00:02:30,030 --> 00:02:35,580 directory. So I have my terminal open, I 46 00:02:35,580 --> 00:02:38,640 am logged in as a root. Now first thing 47 00:02:38,640 --> 00:02:44,179 I want you to do is go to cd /etc. 48 00:02:44,179 --> 00:02:48,990 In here, you will do ls minus l 49 00:02:49,170 --> 00:02:53,460 cron.*, and you run, when you 50 00:02:53,460 --> 00:02:56,670 enter you will see, it will grep, it will 51 00:02:56,670 --> 00:02:59,670 grep everything that starts with cron. So 52 00:02:59,670 --> 00:03:02,580 it's getting cron.deny, cron hourly, 53 00:03:03,810 --> 00:03:06,150 sorry, right here. The directory we have 54 00:03:06,150 --> 00:03:09,150 is cron.monthly, cron.hourly, but the 55 00:03:09,150 --> 00:03:12,120 right way to show you is I will do is ls 56 00:03:12,120 --> 00:03:19,080 minus l grep for cron. So this way, you 57 00:03:19,080 --> 00:03:22,590 will see the directories that I want to 58 00:03:23,520 --> 00:03:25,890 go work for. So you see right here the 59 00:03:25,890 --> 00:03:29,880 cron.daily, cron.hourly, monthly, 60 00:03:31,290 --> 00:03:34,200 and weekly. And this is the crontab, 61 00:03:34,200 --> 00:03:35,970 the actual tab where you go in and 62 00:03:35,970 --> 00:03:38,730 specify manually if you don't want to go 63 00:03:38,730 --> 00:03:41,520 into each daily, hourly, or weekly. So 64 00:03:41,520 --> 00:03:46,590 let's say if I go into cd cron.daily, 65 00:03:48,240 --> 00:03:51,347 and which directory I am in, I'm an /etc/cron.daily 66 00:03:51,347 --> 00:03:53,400 do ls minus l, you will 67 00:03:53,400 --> 00:03:57,420 see it has three different cron, or the 68 00:03:57,420 --> 00:04:01,140 tasks, or the scripts that run daily. 69 00:04:01,710 --> 00:04:05,100 And these are the actual scripts that 70 00:04:05,100 --> 00:04:07,680 were run daily. If you have a script 71 00:04:07,680 --> 00:04:10,950 that you want to run daily, once a day, 72 00:04:11,280 --> 00:04:13,290 then you, all you have to do is put your 73 00:04:13,290 --> 00:04:16,769 script, move it in this directory, which 74 00:04:16,769 --> 00:04:20,610 is cron.daily. If you want to run your 75 00:04:20,610 --> 00:04:24,930 script, hourly, then you go into one 76 00:04:24,930 --> 00:04:29,057 step back and you go into cron.hourly, 77 00:04:29,057 --> 00:04:33,120 and then you add that into this 78 00:04:33,180 --> 00:04:35,460 directory. Your script moved that script 79 00:04:35,460 --> 00:04:38,370 into this directory. Similarly, if you 80 00:04:38,370 --> 00:04:42,720 want it to add or run your script every 81 00:04:42,720 --> 00:04:46,309 month, then you could do cron.monthly. 82 00:04:46,309 --> 00:04:48,930 Go into this directory and do 83 00:04:48,930 --> 00:04:51,090 ls minus l. You'll see there is nothing 84 00:04:51,090 --> 00:04:53,070 right now in that directory. So all you 85 00:04:53,070 --> 00:04:55,650 have to do is move your script to this 86 00:04:55,650 --> 00:04:57,930 directory and by default, it will run 87 00:04:57,990 --> 00:05:02,700 every month. Now question is how or 88 00:05:02,700 --> 00:05:06,330 when does the monthly runs or when daily 89 00:05:06,330 --> 00:05:10,260 runs. So that is specified in when you 90 00:05:10,260 --> 00:05:14,640 do cat /etc/anacrontab and hit 91 00:05:14,670 --> 00:05:17,310 enter, and you will see the timings that 92 00:05:17,310 --> 00:05:21,614 are set right here. So 1 5 cron.daily, 93 00:05:21,614 --> 00:05:23,760 that's the daily time it will run. 94 00:05:24,000 --> 00:05:27,810 7 25, it's the weekly. See period in 95 00:05:27,810 --> 00:05:33,630 days, seven, seven day, delay in minutes, 96 00:05:34,260 --> 00:05:38,667 delays in delay in minute, and job-identifier, 97 00:05:38,667 --> 00:05:40,830 and command, this is a 98 00:05:40,830 --> 00:05:42,630 command it will run. So this is the 99 00:05:42,630 --> 00:05:45,150 timing that it is telling you. These are 100 00:05:45,150 --> 00:05:48,990 the timing that it will run your daily, 101 00:05:48,990 --> 00:05:51,600 weekly or monthly jobs. Now what about 102 00:05:51,600 --> 00:05:53,760 the hourly? The hourly is not specified 103 00:05:53,760 --> 00:05:56,790 here. To view the hourly scheduled time 104 00:05:56,790 --> 00:06:02,670 you have to do cat /etc/cron.d/0hourly, 105 00:06:02,670 --> 00:06:05,010 and you will see 0hourly is 106 00:06:05,010 --> 00:06:09,990 scheduled to run at 01, which is 12:01. 107 00:06:10,170 --> 00:06:12,360 At midnight, every night, it runs. 108 00:06:12,390 --> 00:06:14,580 Anything that is specified in the 109 00:06:14,610 --> 00:06:18,900 hourly, sorry, not midnight, that would 110 00:06:18,900 --> 00:06:22,080 be daily. It is scheduled to run every 111 00:06:22,080 --> 00:06:24,240 one minute after the hour. So it will 112 00:06:24,240 --> 00:06:30,630 run at 12:01, 1:01, 2:01, 3:01. So every, one past 113 00:06:30,630 --> 00:06:33,570 minute, every hour if you define your 114 00:06:33,570 --> 00:06:36,450 script into cron.hourly. So anyway, 115 00:06:36,450 --> 00:06:38,550 this is what I wanted to cover. If you 116 00:06:38,550 --> 00:06:41,040 wanted to go over the cron details and 117 00:06:41,040 --> 00:06:45,000 you don't want to specify cron dot, 118 00:06:45,360 --> 00:06:48,210 crontab minus e. You don't want to write 119 00:06:48,210 --> 00:06:51,510 down into this cron, then you don't have 120 00:06:51,510 --> 00:06:54,060 to, you could simply go into each 121 00:06:54,090 --> 00:06:56,820 individual directory and all you have to 122 00:06:56,820 --> 00:06:59,940 do is put your script in that directory 123 00:06:59,970 --> 00:07:02,790 and let these directories or let these 124 00:07:02,790 --> 00:07:04,980 jobs run as they are scheduled to run. 125 00:07:04,980 --> 00:07:06,795 [No audio]