Regístrese ahora para una mejor cotización personalizada!

Noticias calientes

How to schedule Linux commands - and when you should

Oct, 21, 2024 Hi-network.com
Manuel Breva Colmeiro/Getty Images

Linux has many tricks up its sleeve, which helps make it one of the most powerful and flexible operating systems on the planet. 

Take, for instance, the ability to schedule commands. Say you need to print something, but someone has been using the printer all morning and is showing no signs of letting up. You need to make sure the file in question is printed, but don't trust your memory. This is a greattime to schedule the file to print so thatit'll happen when you're certain the printer will be available.

Also: 5 Linux commands I use to keep my device running smoothly

Whatdo you do? Turn toat.

Whatis the at command?

Theat command allows you to schedule the execution of a single instance of a command or script at a specific time and date and should be installed on your Linux distribution by default.

Essentially,at is run like so:

at [OPTION(s)] execution_time

Here, OPTION(s) is/are various options you can add, and execution_time is the time/date for the command's execution.

Also: How to share folders to your network from Linux

Withat, you can schedule the execution of a command at a specific time, a set number of minutes or hours after the current time, on a specific date/time, or even days into the future -- it's really flexible.

You can even schedule your computer's shutdown at a specific time. This can be handy if you prefer to shut your PC down at night and tend to forget.

How to useat

Let's stick with our example above, printing a file at a specific time. First, command-line printing is handled with the lp command. If you only have one printer connected to your machine, you don't have to tell lp which printer to use. We'll also have to use the echo command and the pipe. It sounds complicated, but it's not. Here's how.

1. Open a terminal window

The first thing you'll need to do is open a terminal window on your Linux distribution. Once you've done that, verifyatis installed with the command:

at -V

You should see something like this in the output:

at version 3.2.5Please report bugs to the Debian bug tracking system (http://bugs.debian.org/)or contact the maintainers ([email protected]).

2. Construct the first part of the command

Remember when I said theat command syntax wasat [OPTION(s)] execution_time? That's just the structure of the command itself, but doesn't include the command you want to run withat

Also: The 4 best Linux desktops based on GNOME - and what I most like about each one

Confused? You won't be. We have to employ theechocommand to construct what we wantatto run. Using our example, we'll print the file zdnet.txt using thelpcommand. For that, we'll use the following:

echo "lp zdnet.txt"

3. Pipe the results of the first command to at

Next, we use the pipe to send the output of the first command to the at command, which looks like this:

echo "lp zdnet.txt"

The output of our first command "lp zdnet.txt" just so happens to be the command to print the file zdnet.txt.

4. Set the time

Let's print the zdnet.txt file two hours from the current time, which would beat now + 2 hours. You could also specify a date. 

Also: Don't run these 5 Linux commands - here's why

Let's say you wanted to print the file at 3pm, five days from the current date, which could be done withat 3pm + 5 days.

5. Put it all together

Our full command now looks like this:

echo "lp zdnet.txt"  at now + 2 hours

If you run that command, you'll see output informing you when the command will be run. For instance, my output was:

warning: commands will be executed using /bin/shjob 1 at Mon Oct 21 10:24:00 2024

Once you've run the command, you can be sure the zdnet.txt file will print two hours from the current time.

Also: The first 5 Linux commands every new user should learn

That's how you use theat command in Linux. I would recommend going through the manual page (man at) to find out more about how to schedule specific times and dates with the command.

Open Source

10 Linux apps I can't do without - and whyLinux and open-source documentation is a mess: Here's the solution6 ways LibreOffice is better than Google Docs for serious writing workThe Linux file system structure explained
  • 10 Linux apps I can't do without - and why
  • Linux and open-source documentation is a mess: Here's the solution
  • 6 ways LibreOffice is better than Google Docs for serious writing work
  • The Linux file system structure explained

tag-icon Etiquetas calientes: tecnología Servicios y Software Sistemas operativos

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.
Our company's operations and information are independent of the manufacturers' positions, nor a part of any listed trademarks company.