Linux Scheduling Commands With at, atq, atrm and batch Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-scheduling-commands-atq-atrm-batch-examples/
PINTEREST
PINTEREST
INSTAGRAM

Scheduling commands in IT environments are important. There are tools like at , atq , atrm , batch . We will look all of them in this tutorial.

Schedule Job At

While scheduling jobs we will use at command. At command have very causal time specification. We will look varying time specification in the next example in detail. Now we simply schedule job.

Schedule Job At

Schedule Job At

We will run mkdir test command  at 20:58 . In order to accomplish this we run following steps.

  • at 20:58 will run following commands at 20:58
  • mkdir test is the command we want to run specified time
  • We can give more than one command for each line of prompt but we can end the commands with CTRL+d which will give an output like <EOT>

Time Formats

at command supports a lot of different type of time specification. Here some of them.

  • noon will run 12:00 PM
  • midnight will run 12:00 AM
  • teatime will run 4:00 PM
  • tomorrow will run next day same time
  • next week will run next week
  • fri will run Friday
  • next monday will run next monday
  • now + 1 hour will run after 1 hour
  • now + 3 weeks will run after 3 weeks

Schedule Job With Relative Time

As we have seen a lot of different time expressions in previous example we can use them in our examples. In this example we will set time relatively which means we will set time according to current time. To specify relative time we will use now time specifiers with count . In the example we will set command to run after 15 minutes.

LEARN MORE  How To Record Screen In Linux?

Schedule Job With Relative Time

Schedule Job With Relative Time

We can see from screenshot that the command is set to run at 21:31 which is after 15 minutes from now. We can see that this job is numbered 2

View All The Schedules Jobs

In a busy system there may be a lot of scheduled jobs. Listing them can be done with atq command.

View All The Schedules Jobs

View All The Schedules Jobs

We can see that there is only one job in the list. This job is numbered as 2 . This job will e run at Thu Mar 9 21:31:00 . The job is created by user ismail

Remove/Delete A Scheduled Jobs

We can also remove jobs that not run. We need the job ID which can be listed with atq . We will provide job ID to the atrm command like below. We will remove job ID 2 .

Remove/Delete A Scheduled Jobs

Remove/Delete A Scheduled Jobs

Execute Jobs According to Load Average

We can set for different times for our jobs. But some times just setting time is not enough or not suitable for our situation. There is an alternative way to schedule command We can use batch command to run commands if load average is less than 1.5 . In the example we will run echo "Run reports"

Execute Jobs According to Load Average

Execute Jobs According to Load Average

Reload Jobs From A File

Another useful feature is reading commands from a file. As we know commands are read from an interactive shell. We can provide commands to be run at scheduled time. We will use -f option and the command file name to use this feature. In the example we will read commands file named myjobs.txt and run them after 2 days.

LEARN MORE  Linux Cp or Copy Command

Reload Jobs From A File

Reload Jobs From A File

Allow and Deny User To Schedule Job

By default all users in Linux system can create scheduled jobs. This may create some problems or security issues or simply it is unwanted situation. We can set rules to allow or deny some user from scheduling commands.

There is two configuration file to configure this.

  • at.allow is used to set allowed users
  • at.deny is used to set denied users
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-scheduling-commands-atq-atrm-batch-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)