How to automate daily jobs on Linux using (at)

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

First we need to know everyone does the same specific task everyday manually and that may waste a lot of time especially when we have important tasks or your day was busy with a lot of other tasks .. but we bring the best solution that will save a lot of time to do other important things. 

So Let’s Start with (at): so at is a command on Linux used to execute command in a particular time once

How to install at ?

Install at on Debian(Ubuntu\Kali): 

Before everything, update your system, and therefore use this command.

apt-get update && apt-get upgrade

The second thing, install the at package

 
sudo apt install at -y 

You can check it working well when the daemon is running by writing this command on the terminal and ensure that the atd.service is active (running)

sudo  systemctl status atd.service 

If the atd.service is disabled or inactive write this two commands on terminal 

sudo systemctl enable atd.service
sudo  systemctl start atd.service 

Install at on Centos\Redhat\Fedora:

sudo yum install at -y 

How to use it ? 

Only users with administrative privileges can use at command 

You can control who can create jobs using at by allowing specific users or denying others 

  • Open  your terminal 
  • Write command : 
vi  /etc/at.deny  
  • And write the user that you will prevent it to create jobs using at
  • To allow specific user write the following 
vi /etc/at.allow
  • Add user that you will allow it creating the jobs using at 

Hint : maybe you can’t find the file (at.allow) .. you can create it first and add users on it 

You can use it simply by executing simple tasks in a particular time.

Open your terminal and write this command 

at    <time you want to execute task>

Write the command that you want to execute.

After finishing press Ctrl + D   >> to save the job and exit 

I executed an archiving task  for two files at a specific time .

You can execute tasks in the script file as shown below.

Simple script that ping to google with count 2 and save output to file
at  <time> -f <Script File> 

You can edit the time formatting with the following forms 

at  Friday +30 minutescoming Friday at a time 30 minutes later than the current time
at 4am + 3 days at  4 pm 3 days from now 
at  13:00 080521at  13:00 AUG 05 2021

To check the list of all tasks will be executed by at : 

Open the terminal and write the following commands 

atq    or  at -l 

To remove one of this task: write the command

atrm < the number of task >

Conclusion

Finally, the at utility reads commands from standard input and executes them at a particular time 

So for more information about all available options of the at command type in your terminal

man at

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook