1 00:00:06,740 --> 00:00:11,795 Okay, in this video I want to show you what's going on 2 00:00:11,795 --> 00:00:16,850 with Cron. So to start with sudo systemctl status on crond service. 3 00:00:18,530 --> 00:00:22,079 Sometimes it's crony, sometimes it's cron, depending on your distribution. 4 00:00:22,079 --> 00:00:25,629 But here we can see that cron is actually running. 5 00:00:26,750 --> 00:00:30,269 Now this cron service has its main configuration file. 6 00:00:31,350 --> 00:00:36,630 If I use sudo cat on etc crontab then we can see what it is like. 7 00:00:37,689 --> 00:00:42,543 Historically you would put everything in here. That's not how we do it nowadays anymore. But I 8 00:00:42,543 --> 00:00:47,396 like it because it has an explanation of the times. So it has five positions to indicate 9 00:00:47,396 --> 00:00:52,250 the minute, the hour, the day of the month, the month and the day of the week. 10 00:00:53,060 --> 00:00:56,439 And based on that I can create my own crontab. 11 00:00:57,100 --> 00:01:03,333 And in order to do so, I'm going to use sudo crontab E 12 00:01:03,333 --> 00:01:09,566 for edit, U for lynda. I want to create a crontab for user 13 00:01:09,566 --> 00:01:15,799 lynda where I'm going to set star star star star star. 14 00:01:16,299 --> 00:01:21,299 Oh my goodness. Really? Yeah, I want to do it every minute because I want to show you that it works. 15 00:01:21,959 --> 00:01:23,780 And I am going to use logger. 16 00:01:24,959 --> 00:01:29,260 Greetings from Linda. 17 00:01:30,560 --> 00:01:36,560 Now what did we just do? Well, I just created a new cront app for user 18 00:01:36,560 --> 00:01:42,560 Lynda, E started the editor and U is doing it for a specific user. That's what 19 00:01:42,560 --> 00:01:48,560 I like about crontab. You can easily create tasks that will be executed by specific users. 20 00:01:49,500 --> 00:01:55,950 Now normally it will do so on top of the minute. That's why I've done every minute. In real life you don't want to do it every minute. 21 00:01:56,730 --> 00:02:00,120 But now I want to make sure that we can see a result. 22 00:02:00,659 --> 00:02:04,750 So are we already on the top of the minute? Well, seven 23 00:02:04,750 --> 00:02:08,840 more seconds of waiting and then we should see the result. 24 00:02:09,979 --> 00:02:12,919 So I'm going to use sudo journal ctl. 25 00:02:14,090 --> 00:02:20,485 Now, what is journal CTL showing? Well, journal CTL should show on top of the minute and oh 26 00:02:20,485 --> 00:02:26,879 boy, a lot of things have happened on top of the minute. But that includes greetings from Linda. 27 00:02:27,439 --> 00:02:31,084 Journalctl is the easiest way to get more information out of the 28 00:02:31,084 --> 00:02:34,729 systemd journal. That's a topic we'll talk about later by the way. 29 00:02:35,550 --> 00:02:41,166 So this is one thing that you can do with cron. Now, depending 30 00:02:41,166 --> 00:02:46,783 on your distribution, you might have Kron automatically pickup configuration files if that 31 00:02:46,783 --> 00:02:52,400 is the case. Well, you are going to find out by using lsetccronestar. 32 00:02:54,780 --> 00:02:59,634 And what you would be looking for is if you have anything, any directories and any files 33 00:02:59,634 --> 00:03:04,490 in there here on Centos we don't. But let's check out how it works on Ubuntu. 34 00:03:05,169 --> 00:03:09,740 So here I'm on Ubuntu and I'm using LS on Etc. 35 00:03:11,719 --> 00:03:17,665 Cron and there you can see that there's a couple of subdirectories. So there is the 36 00:03:17,665 --> 00:03:23,610 Etc Cron D which has cron jobs that will be picked up by the cron daemon. 37 00:03:24,110 --> 00:03:28,665 There is Etc. Cron daily, weekly, monthly, which is cron jobs 38 00:03:28,665 --> 00:03:33,220 that will be executed at a daily, weekly and monthly basis. 39 00:03:33,719 --> 00:03:35,219 Like mandb for instance. 40 00:03:35,979 --> 00:03:41,463 So this Ubuntu system is running mandb every day now everything in the cron 41 00:03:41,463 --> 00:03:46,946 daily, weekly or monthly directories is a shell script that will be picked up 42 00:03:46,946 --> 00:03:52,430 automatically and stuff in etc. Cron D should have regular cron syntax. 43 00:03:53,110 --> 00:03:57,509 So when I would check etc. Cron D 44 00:03:57,509 --> 00:04:01,909 systat we can see what it is doing. 45 00:04:02,750 --> 00:04:06,189 I like this command because it has a little bit more complex syntax. 46 00:04:07,090 --> 00:04:12,016 What do you think of this for 5,55,10 that means starting at minute 5 47 00:04:12,016 --> 00:04:16,943 until minute 55 of every hour of every day of the month, in every 48 00:04:16,943 --> 00:04:21,870 month and every day of the week it will run this command. 49 00:04:22,750 --> 00:04:28,009 We also see a second one, 5923 which means every day 50 00:04:28,009 --> 00:04:33,269 at hour 23, minute 59 it will run this other command. 51 00:04:34,269 --> 00:04:39,389 That is what these cron files may look like now. You should know that 52 00:04:39,389 --> 00:04:44,509 cron is from the past and distributions are moving on to systemd timers nowadays.