If you've been using it for a while, you may have found yourself doing redundant tasks to manage the system. Scripts are a good way to remedy this, but you still have to manually execute the scripts. This, however, is remedied through automation and Cron, which is the tool that is used to execute tasks as times/days/months specified by the user. In this tutorial, we'll introduce at, cronjobs, and their ability to inflate quality-of-life for any user willing to learn them.
The "at" command
The command at is used to schedule one-time jobs that may occur later in the day, but you might not be present at the terminal to do, or do not want to subject to human error by missing the time slot. We will first want to make sure we have at installed by inputting:
sudo apt install at
You should see something similar to the screen below.
We can now create our first at job. In order to do so, we can input the following:
at 2300
You will then be prompted to input a series of commands. Pressing ctrl+d once you are done inputting the commands will end the prompts, and schedule those commands to be executed at the specified time, 11 pm in the sample input above.
Note that at does not output to the terminal, so you won't see any output in the example above. In order to make sure that the command executed on time, we can instead redirect the output to a file like so:
echo Hello World! > at.txt
Note that it is even possible to run scripts from the at command, allowing you to schedule a series of tasks for the day ahead of time:
Again, it is important to note that the at command does not send output to the terminal, so in order to save the output, you must redirect the output into a file.
The at command is extremely versatile and useful for those needing to complete daily tasks at a specified time. It allows you to schedule at commands in advance though; you must input the command on the day that you'd like to use it. Another utility that will allow us to schedule these commands days/months in advance is called cron, which we'll get into at a later time.
Comments
0 comments
Please sign in to leave a comment.