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.

$ at 20:58

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

will run following commands at mkdir test is the command we want to run specified time

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

will run 12:00 PM midnight will run 12:00 AM

will run 12:00 AM teatime will run 4:00 PM

will run 4:00 PM tomorrow will run next day same time

will run next day same time next week will run next week

will run next week fri will run Friday

will run Friday next monday will run next monday

will run next monday now + 1 hour will run after 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.

$ at now + 15 minutes

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.

$ atq

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 .

$ atrm 2

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"

$ batch

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.

$ at -f myjobs.txt now + 2 days

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.