atq1_使用at,atq,atrm和batchLinux调度命令示例

atq1

atq1

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

在IT环境中安排命令很重要。 有一些工具,例如atatqatrmbatch 。 我们将在本教程中查找所有这些内容。

安排工作时间 (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命令。 在命令中有非常因果的时间规范。 在下一个示例中,我们将详细介绍变化的时间规范。 现在我们只需安排工作。

$ at 20:58
Schedule Job At
Schedule Job At
安排工作时间

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

我们将在20:58运行mkdir test命令。 为了做到这一点,我们运行以下步骤。

  • at 20:58 will run following commands at 20:58

    at 20:58将在运行下面的命令20:58

  • mkdir test is the command we want to run specified time

    mkdir test是我们要在指定时间运行的命令

  • 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>

    我们可以为每一行提示提供多个命令,但可以使用CTRL+d结束命令,这将给出类似<EOT>的输出

时间格式(Time Formats)

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

at命令支持许多不同类型的时间规范。 这里有一些。

  • noon will run 12:00 PM

    noon将运行12:00 PM

  • midnight will run 12:00 AM

    midnight将运行12:00 AM

  • teatime will run 4:00 PM

    teatime将运行4:00 PM

  • tomorrow will run next day same time

    tomorrow将同时运行

  • next week will run next week

    next week将在下周运行

  • fri will run Friday

    fri将运行周五

  • next monday will run next monday

    next monday将在下周一运行

  • now + 1 hour will run after 1 hour

    now + 1 hour将在1小时后运行

  • now + 3 weeks will run after 3 weeks

    now + 3 weeks将在3周后运行

安排相对时间的工作(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.

正如我们在前面的示例中看到的很多不同的时间表达式一样,我们可以在示例中使用它们。 在此示例中,我们将相对设置时间,这意味着我们将根据当前时间设置时间。 为了指定相对时间,我们将now使用带有count时间说明符。 在示例中,我们将命令设置为在15分钟后运行。

$ at now + 15 minutes
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

从屏幕截图中我们可以看到,该命令设置为从现在开始15分钟后的21:31运行。 我们可以看到这份工作编号为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命令完成。

$ atq
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

我们可以看到列表中只有一项工作。 这项工作被编号为2 。 这项工作将在Thu Mar 9 21:31:00 。 该作业由用户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 .

我们还可以删除未运行的作业。 我们需要可以用atq列出的工作ID。 我们将为atrm命令提供工作ID,如下所示。 我们将删除作业ID 2

$ atrm 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"

我们可以为工作设置不同的时间。 但是有时候仅仅设定时间是不够的,或者不适合我们的情况。 还有另一种调度命令的方法,如果平均负载小于1.5则可以使用batch命令来运行命令。 在示例中,我们将运行echo "Run reports"

$ batch
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.

另一个有用的功能是从文件读取命令。 众所周知,命令是从交互式外壳读取的。 我们可以提供要在预定时间运行的命令。 我们将使用-f选项和命令文件名来使用此功能。 在示例中,我们将读取名为myjobs.txt命令文件,并在两天后运行它们。

$ at -f myjobs.txt now + 2 days
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.

默认情况下,Linux系统中的所有用户都可以创建计划的作业。 这可能会引起一些问题或安全性问题,或者仅仅是不希望的情况。 我们可以设置规则以允许或拒绝某些用户调度命令。

LEARN MORE  Batch File Commands For Windows MSDOS
了解更多用于Windows MSDOS的批处理文件命令

There is two configuration file to configure this.

有两个配置文件可以对此进行配置。

  • at.allow is used to set allowed users

    at.allow用于设置允许的用户

  • at.deny is used to set denied users

    at.deny用于设置拒绝的用户

翻译自: https://www.poftut.com/linux-scheduling-commands-atq-atrm-batch-examples/

atq1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值