We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Analysis Summary
Worth Noting
Positive elements
- This video provides a practical, high-quality lesson on integrating Bash scripts with systemd timers, a fundamental skill for Linux automation.
Influence Dimensions
How are these scored?About this analysis
Knowing about these techniques makes them visible, not powerless. The ones that work best on you are the ones that match beliefs you already hold.
This analysis is a tool for your own thinking — what you do with it is up to you.
Related content covering similar topics.
Linux Terminal Tips & Tricks #13 - systemd-inhibit - Block reboot, shutdown, suspend events
sleepyeyesvince
🎬 Download and Play YouTube Clips with bash/Go
RWXROB
ButterTodo 🧈 - I Made a Todo App Nobody Asked For
JustAGuy Linux
How to Automate Linux Backups Using rsync and systemd
Learn Linux TV
🐍 Python prompt to load venv in 13 lines of .bashrc
RWXROB
Transcript
Hello again everyone and welcome back to Learn Linux TV. In today's video, we're going to work on a fun hands-on lab. What we're going to do is build a message of the day that'll appear anytime we log into our system, and it'll show us helpful system information. In addition, I'll also show you later in the video how to add an optional joke of the day as well. And for those of you that are learning, this project will have us go over a few very important Linux concepts. For example, we'll be writing a bash script, a systemd service, as well as a systemd timer. So, in this video, not only will you end up with a very awesome message of the day, you'll also learn some important Linux skills as well. And this is what it looks like. As you can see right here, the message of the day includes system information like I mentioned, and it's really helpful. Now, the solution I'm going to show you isn't going to have the ASI art that Neoofetch is known for, but it is going to have the same use case. But if you've been using Linux for a while, you might be immediately reminded of a tool called Neoetch, which does exactly the same thing. But Neofetch is no longer maintained and it's not recommended for use. And while other solutions have come around that also show system information, it's always better if we can avoid installing anything at all. And the thing is, everything we need to recreate this exact same thing is built right into Linux. Now, there will be a fun bonus tip near the end of the video which will require an additional package, but it is completely optional. Now, there is one requirement though, and that is that your distribution will need to use systemd. This activity will not work on a system that doesn't use it. Most distros nowadays, such as Arch, Debian, Fedora, Mint, Ubuntu, and a number of others all use systemd. So, for the majority of you, there really shouldn't be anything extra you'll need to do in order to prepare. All you really need is a Linux installation, and that's about it. and we'll get started in just a moment. But before we do, I just wanted to mention that you should consider becoming a channel member. If you enjoy the content here and want a slightly more streamlined experience, becoming a member is a great way to do that. Channel members get access to adree versions of videos along with early access to select uploads. So that way you can watch new content a bit sooner without any interruptions. This is completely optional, of course, but it's a nice way to support the channel. If you find yourself regularly coming back here and getting value from my videos, if that sounds like something that you might be interested in, you could check out the membership options by clicking the join button below this video. And a big thank you to everyone who's already become a member. Your support makes a real difference and it helps me keep creating the kind of Linux content that you come here for. As always, thank you guys so much for supporting Learn Linux TV. I really appreciate it. Now, let's dive into today's activity. [music] First, let's see what today's hands-on lab will look like once we're finished. What I'll do is log into one of my Linux servers. I'll just choose one at random. And once I do that, you'll see the result immediately. So, I'll press enter and let's see what happens. And take a look at this. What you see right here is the message of the day file that I use in production. And what this will provide is a lot of useful information as soon as we log into a server. For example, we see the host name, we see the machine ID, we see the operating system, kernel, architecture, as well as various other things. And also, we see today's joke of the day. Now, that's completely optional. And you may or may not want to have something like that in production, but it is something that I add to my servers because it makes it a lot more fun. But if you want to know how I did that, what I'll do is show you how I did that during a bonus tip towards the end of the video. Now, before I go any further, I want to explain a little bit more about what's going on here. As I just showed you, as soon as I logged into a server, I saw some helpful information immediately. Anyway, at this point, you might be curious where that information came from. So, what I'll do right now is show you exactly where it came from. On most Linux systems, you'll have a message of the day file. It's typically located in / etsy/motd as you see right here. And if I show you the contents of that file, you'll see the exact same information. What I'm going to do is actually empty the file and I'm going to simply change it to hello world. And now what I'll do is log out. I'll log back in and check it out. Now I see hello world when I log into the server. And again, that information came from this file right here. And continuing, what I'm going to do right now is show you how the information in the original message of the day file was generated. Obviously, if I was to create that file from scratch, that would take a long time. So, we definitely don't want to do that. What we should do instead is automate the process. And actually, that's what I've done. If I list the contents of my user local bin directory, you'll see that I have a message of the day script. It's the third one down. And in my case, that's what actually generates the information that you see in the message of the day file. So, if I cap the contents of that file again, you'll see that it still says hello world. However, what I'll do right now is run that script that I created. And next, what I'll do is check the contents of the message of the day file again. As you can see, it's completely regenerated. And also, we got a new joke. How cool is that? So, now what I'd like to do is show you exactly how you can set this up. And along the way, you'll learn more about how Linux works under the hood. I'll show you how to create a script that'll automate the process. And I'll even show you how to create what's called a systemd timer. And what that'll do is automatically run our script for us regularly. So that way the message of the day file will be regenerated every so often. So let's do it. And the first thing we're going to do is learn a new command. And that command is hostnamect cl. And if you think that information looks a little familiar, well, you're right. It's the same information that was shown in the message of the day file that you saw earlier. So as you can see, if you run hostname ctl, you'll see system information. Now, as an aside, the hostname ctl command isn't only used to view system information. You could use it for other things as well. For example, you could also use it to set your systems host name, but I'm not going to cover this command in any more detail during this video since it's beyond the scope, and I've also covered it in a previous video. So, if you want to check out a video that covers it in more detail, then you can view that video, and I'll leave a card for that video right about here. Anyway, at this point, what I've done is I've deleted my message of the day file. I deleted the script and everything related to it. I basically wiped out my entire lab server. And the reason I've done that is because I want to show you guys how to build this from scratch. In fact, if I log back into that server, you'll see a completely different message of the day. And this one in particular is the default that came with Debian. So basically, yeah, I completely reset my server so that way I could show you everything from scratch. So let's do it. And the first thing we're going to do is work on the bash script. We'll need to use sudo because we'll be making changes to the system. We'll need to use a text editor and it doesn't matter which one, but I'll be using nano just because it's easier to explain when it comes to producing a tutorial. And the file that we'll be creating will be under user local bin. And we'll name it. So I'll press enter and let's start writing it. And the first thing we'll do is clarify that this is going to be a bash script. We'll type printf. And if you haven't used that command before, it's very similar to echo. Has a similar purpose. It essentially allows you to print text on the screen. That's an oversimplification of what this does. But print f differs from echo because it gives us the ability to add additional formatting. And what we'll do is type double quotes. and inside the double quotes. Now, you don't have to include a line break at the beginning, but I think it looks a little bit better, display the text system information. We'll add another line break. And what we'll do is redirect the output into the message of the day file. So, at this point, when this command runs, it's going to completely wipe out whatever might be in that file right now and replace it with only system information. Next, we'll use print f again. And I'll type out the rest of the command. We'll use percent s because we want to print a string. And then we want a line break right after that string. And then next, I'm going to have a space. And then in single quotes, I'll have three hyphens. And then I'm going to use two greater than symbols to activate append mode, which is going to send the three dashes to the end of the message of the day file. Now, you might be wondering why this command looks completely different than the previous one. And setting it up this way makes sure that the three dashes are treated as a string no matter what. Anyway, continuing things are going to get a bit more interesting. What we're going to do is run host name ctl and what we'll do is redirect the output of that into the message of the day file. And believe it or not, that's it. That's all we needed for this particular script. Now, we will be expanding on this a bit later, but for now, this is all we'll need. Anyway, I'll save the file. Now, it's not marked executable like the other ones are. So, we'll need to fix that. And it's pretty easy to do. So what we'll do is run sudo chmod and we'll add the execute bit and we'll run that against our script. And now as you can see it's executable. And the next thing we'll do is have a bit of fun and test it out. If I c the current contents of my Etsy message of the day file, we'll see that it's still at Debian's default. However, if I run the script and then I check the contents again, you'll see that it changed. And to further test it, I'll log out and I log back in. And as you can see, the message of the day file works. We now see system information instead of the default message of the day as soon as we log into the server. However, there is one problem though. We have to run that script manually. It would certainly be a lot better if we had something that would run our script for us automatically so that way we didn't have to remember to do it. And in fact, that's exactly what we're going to set up right now. What we're going to do is set up a systemd timer. But first, there is a prerequisite that we'll need to take care of. Basically, what a systemd timer does is run a service. So, we'll need this service. Otherwise, the timer isn't going to have anything to run. So, to set up the service, what we'll do is use sudo. And then we'll use a text editor. And we're going to create a new systemd service. And we're going to save it under / etsy/systemd/system. And we're going to name it.service service just like this. So essentially what we're going to do is create a service to run the script that we just created. And the configuration will have a few different categories. The first one is going to be unit. It's going to be in square brackets as you see right here. We're going to type description then equal. and we'll give our service a helpful description. Next, we'll type after equal. We want this service to start only after the network is online. And that'll give it a nice order of operations. Next, we'll type once and then equal and again network online.target target. Next, what we'll do is set up a new category. We'll call it service. We'll add type and we'll set the type to oneshot. Now, when it comes to systemd services, there are several different types, and it's beyond the scope to go over all of them, but the basic idea is that we have a oneshot type right here, which just refers to something that triggers just one time. We just basically want something that's going to run the message of the day script and then immediately exit. And that's exactly what Oneshot does. Next, we'll add exact start. Notice that the E and the S are capitalized. So it might be a good idea to real quick just spot check the file and make sure you have everything on your end like I do on my end so far. Anyway, we have exact start and then equal and then / user/local/bin/otd. We want our script to run. So that's why we added the path and the name to our script right there. And now we'll create another section. This one for install. And when it comes to wanted by, we're just going to set the default for that. And that has to do with dependencies. You could essentially make one service depend on another. It's beyond the scope of this video to dive too deeply into systemd services. I want to show you how these work at a very basic level in this video, but again, I have other videos that covers this subject if you want to learn more about it. Anyway, that's our systemd service. So, what I'll do is save the file. And now that we have that service file, what we're going to do is refresh systemd itself to make sure that it's aware of that. And to do that, I'll run sudo systemctl demon hyphen reload. Press enter. And we should be good to go. But let's test it to make sure that it's working. And the first thing I'm going to do is type systemctl status and thenotd.service. So I'll press enter. Under active we have inactive dead which sounds kind of harsh but actually in our case that's perfectly fine. Reason being the message of the day script is only going to execute and then immediately exit. So it's not something that's ever going to show as active in the first place. Now, as a fun experiment, what we're going to do is check the contents of our Etsy message of the day file, which in my case is the updated one from earlier. So, what I'm going to do, change it back to hello world. And there we have it. Now what I'm going to do is start the systemd service that we created. And for that I'll run sudo and then systemct ctl. I want to start a service. And the service that I want to start is the service that we just created. Now what I'll do is check the status and it did run the time stamp matches and now we can see that the message of the day file was just updated. How cool is that? So our systemd service was able to run our script. That's pretty cool. However, everything that we've created during this tutorial so far is going to come full circle. We'll be creating a systemd timer that'll tie it all together. We'll get back to the video in just a moment, but I wanted to mention that we Linux users, well, we overengineer just about everything. I mean, we'll spend 20 minutes scripting something that a checkbox could have fixed, automate a task that we end up only doing once, or setting up multifactor authentication on a HomeLab app that literally no one else can access. And that's just scratching the surface. But imagine if we spent as much time on our appearance as we do over complicating things. If we did, we'd look amazing. But instead, we're so busy tuning config files that most of our wardrobe was probably purchased well before the pandemic. And if you want to keep obsessing over terminals, desktop environments, distros, and config files and still look good while doing it, then you might want to check out the Learn Linux TV merch shop. It's a store for people who care about Linux customization and coffee. and probably in that order. You'll find shirts, hats, buttons, mouse pads, bags, and more. Whether you want to show off your favorite dro, have a little fun, or even warn people about your obsession, there's probably something in the shop just for you. And it's not just about revealing to the world that you run Arch. Although, yeah, that is important. There's practical items, too, such as the T-Max cheat sheet, mouse pad, reference sheets, and other genuinely useful items. Every purchase helps support the channel, so grab yourself something great. You can check out the shop at merch.learnline.tv. And as always, I really appreciate you guys. Thank you so much for checking out the shop and supporting the channel. I really appreciate it. And now, let's get back to the video. And to do that, we'll again use sudo. We'll use a text editor and the path is going to again be / etsy/systemd/system and the unit file that we'll be creating isotd timer and the syntax of this file will be very similar to the service file that we created earlier. We'll start by creating a unit section description equals And we'll just give it any description we feel is appropriate. Next, we'll add a section called timer. We're going to set persistent to true, and that's going to make sure that this particular timer always runs even if its previous runtime was skipped or missed. Next, we have on boots sec. And I'm setting that equal to 2M, which is short for 2 minutes. And the reason why I put that on my systems is because I have a number of scripts that run during the startup process. And I want to make sure that the message of the day file is not being generated before those finish. In my case, 2 minutes is arbitrary. It really doesn't matter, but I'm just including the same option that I use in production. Anyway, next we have onunit active sec. And this is actually going to allow us to configure how frequently our message of the day file is being updated. In my case, I have it set to 1 hour, but you can set it to something else if you want this to happen more or less frequently. Next, I'm creating an install section. Then I have wanted by and I'm setting that equal to timers.target. That's all there is to it. So, what I'll do is save the file. And at this point, we've created everything that we need. But before we go any further, though, I just want to point out something that's very important, and it's actually critical for this to work at all. If I list the contents of my Etsy systemd system directory, the name portion of the file name needs to match. One needs to be a service, and the other needs to be a timer. Basically, whenever the timer runs, it's going to expect to find a service with the same name. Continuing, now that we've created a systemd timer, we'll need to refresh systemd itself to make sure that it's aware of that timer. And then next, what we can do is check the status of the timer that we just created. And as you can see, the message of the day timer is actually recognized by systemd. And in fact, under triggers, notice that it automatically knows that it needs to trigger MOOTD.service. But we also see that it's inactive and it's also disabled. Now, the important thing to pay attention to is that both of these are disabled. But what exactly does that mean? Well, if you didn't already know, a service or timer that's set to disabled will not start automatically when the system starts. So, essentially that means manual mode. But if you do enable a service or timer, then it will start at boot time. But which one should we enable? Should we enable both or just one of them? Well, that's an important distinction that I wanted to bring up, and it does confuse some people. So, basically, the logic goes like this. you shouldn't need to enable the service, meaning set it up to start at boot time. If you have a timer, that's just going to start it anyway. So, what we'll do is leave the service disabled and we'll enable the timer. And to do that, we'll run sudo and then systemctl. We want to enable a unit. And in particular, we want to enable our timer. Enable only means that it's going to start at boot time, but the system is already booted. So, we'll also start the timer and we'll check the status. And everything looks a lot better. The timer status has changed to active waiting. It's enabled, which is pretty cool. And it also shows us the next time it's going to run. So, essentially, the systemd timer is going to start the service and the service will start the script. And that's essentially how a systemd timer works. Now, at this point, we're going to move away from the topic of systemd timers. But I wanted to mention though that if you are interested in learning more about systemd timers, I do have a dedicated video on that topic and I'll leave a card for that video right about here. And now we've actually reached the end of the tutorial. However, I want to give you guys a bonus tip. Earlier in the video, you saw that my message of the day script included a joke of the day section. So, what I'm going to do is show you how to build that into your script right now. But before we dive in, I just need to mention that you may or may not want to implement something like this at work, especially depending on your seniority level. After all, this is a completely useless tip, but to be fair, it is a lot of fun. Anyway, here's how we'll set it up. What we're going to do is open up our message of the day script. And what we'll do is add a completely new section. I'll just add a quick comment regarding what this particular section is going to be doing. And what we'll do is create a variable named fortune. And we'll set that equal to/ user/game/fortune. And then next what we'll do is write an if statement. And I'm going to include this code right here to start the if statement. It's going to be checking for the existence of a file. That's what - F happens to be. And we include a dollar sign when we want to specifically refer to a variable. And we're going to use the variable fortune right here, which we have set equal to/ user/game/fortune. And that just makes sure that we don't have to type this multiple times. Anyway, we're going to use print f. We'll add two line breaks and then joke of the day and another line break. And what we'll do is append this to the end of the message of the day file. And similar to how we did it before, I'm going to print three hyphens. And I'll send that to the end of the file as well. Dollar sign fortune. And again, that's referring to the variable. I'll use the option - s. And that's going to limit the fortunes, as they're called, to the shorter ones. We'll set the character limit to 150. We want to make sure that we don't see any jokes that are longer than that because it'll just take up too much room. As you probably guessed, we'll send it to the end of the file. And then we'll close the if statement. So, what I'll do right now is run the script and we'll see what it does. And now I'll check the contents again. And well, we don't see a joke. But actually, that's expected. If I bring up the script again, you'll recall that almost the entirety of the joke section is within one if statement. But the thing is, the fortune command is not installed on the system. So, it's not able to find it. And since the script isn't able to find it, then the statements under the if statement will never run. Now, if you haven't ever heard of the fortune command before, you could use it to, well, show a fortune, basically a joke on your terminal. In fact, I've covered the fortune command in its own dedicated video. So, I'll leave a card for that video right about here if you want to learn more about it. Anyway, now what I'll do is install the fortune command, which should activate the second section. And to do that, we'll again use sudo then apt install. And the package that we'll need to install is fortun. So I'll press enter. And it's a very small package. In fact, it's already installed. Now what I'll do is run the script manually. So I'll start the service. We'll check the status. We can see that it ran and now the joke of the day is present. How fun is that? And of course, if you want to disable this feature, all you have to do is remove the package. But at this point, you now have your very own message of the day system. We see helpful system information as well as an optional joke. And there's our video. In this video, we set up a message of the day service that will show us system information as soon as we log into our server, as well as an optional joke. I really hope you enjoyed this video. If you did, then be sure to click that like button to let YouTube know. And also, if you haven't already done so, subscribe to Learn Linux TV for the latest in Linux. I release new content each and every week and I'd love to have you aboard. Anyway, thank you so much for checking out this video and I'll see you in the next one. [music] [music] >> [music] [music]
Video description
Want to show system information at login in Linux—without relying on neofetch? In this hands-on Linux project, you’ll build a custom Message of the Day (MOTD) that displays live system info every time you log in. This video is designed as a learn-by-doing Linux project. You’ll write a Bash script, create a systemd service, and set up a systemd timer to automatically regenerate your MOTD. By the end, you’ll have a clean, professional login message that works across reboots and logins—no manual commands required. *🛍️ Support The Channel and Get Awesome Linux Swag!* Head on over to the Learn Linux TV Merch Shop and check out some great Linux-themed gear, including (but not limited to) T-shirts, drinkware, buttons, stickers and more! • "apt install coffee" T-Shirt ➜ https://learnlinux.link/apt-install-coffee • "sudo" T-Shirt ➜ https://learnlinux.link/sudo-shirt • Linux Commands Cheat Sheet ➜ https://learnlinux.link/linux-commands • "May Spontaneously Talk About Linux" T-Shirt ➜ https://learnlinux.link/talk-about-linux-shirt • "Dark Side of the Terminal" T-Shirt ➜ https://learnlinux.link/dark-side-shirt • Lots more ➜ https://merch.learnlinux.tv _Use coupon code "LINUXFAN" to get 10% off your entire order ➜ https://merch.learnlinux.tv_ *❤️ Consider becoming a Channel Member* Support Linux Learning and gain acess to exclusive perks, such as ad-free content and early access to select videos. Your support really helps!!! Join here ➜ https://learnlinux.link/member *🐧 Other Ways to Support Learn Linux TV* • Channel Membership ➜ https://learnlinux.link/member • Patreon ➜ https://learnlinux.link/patron • Spin up your very own Linux server ➜ https://learnlinux.link/digitalocean • Linux swag ➜ https://merch.learnlinux.tv • Check out Netdata ➜ https://learnlinux.link/netdata • Jay's Gear ➜ https://learnlinux.link/amazon _Note: Royalties and/or commission is earned from each of the above links_ *🕐 Time Codes* 00:00 - Linux MOTD Project: Custom Login System Info 01:48 - Support Learn Linux TV (Channel Memberships) 02:56 - MOTD Explained: A Neofetch Alternative at Login 07:23 - Bash Script Project: Generate a Custom MOTD 11:05 - systemd Service for MOTD Automation 16:50 - Support LLTV and grab some Awesome Linux Swag! 18:24 - systemd Timer: Update MOTD Automatically 23:14 - Fun MOTD Feature: Add a "Joke of the Day" *🎓 Full Linux Courses* • Linux Crash Course ➜ https://linux.video/cc • tmux ➜ https://linux.video/tmux • vim ➜ https://linux.video/vim • Bash Scripting ➜ https://linux.video/bash • Proxmox VE ➜ https://linux.video/pve • Ansible (Udemy) ➜ https://learnlinux.link/ansible • Linux Essentials (Udemy) ➜ https://learnlinux.link/linux-essentials *🎓 More About Learn Linux TV* • Main site ➜ https://www.learnlinux.tv • Community Forums ➜ https://community.learnlinux.tv • Github Account ➜ https://github.com/LearnLinuxTV • Content Ethics ➜ https://www.learnlinux.tv/content-ethics • Request Paid Assistance ➜ https://www.learnlinux.tv/request-assistance ⚠️ Use Content Responsibly Learn Linux TV shares technical content intended to teach and help you, but it comes with no warranty. The channel is not liable for any damages from its use. Always ensure you have proper permissions, follow company policies, and comply with all applicable laws while working with infrastructure. #Linux #MOTD #LearnLinux #LinuxProject #LearnLinuxTV