失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > atq1_使用at atq atrm和batchLinux调度命令示例

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

时间:2019-07-24 05:24:54

相关推荐

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

atq1

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

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

安排工作时间 (Schedule Job At)

While scheduling jobs we will useatcommand. 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
安排工作时间

We will runmkdir testcommand at20:58. In order to accomplish this we run following steps.

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

at 20:58will run following commands at20:58

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

mkdir testis 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 withCTRL+dwhich will give an output like<EOT>

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

时间格式(Time Formats)

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

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

noonwill run 12:00 PM

noon将运行12:00 PM

midnightwill run 12:00 AM

midnight将运行12:00 AM

teatimewill run 4:00 PM

teatime将运行4:00 PM

tomorrowwill runnext day same time

tomorrow将同时运行

next weekwill run next week

next week将在下周运行

friwill run Friday

fri将运行周五

next mondaywill run next monday

next monday将在下周一运行

now + 1 hourwill run after 1 hour

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

now + 3 weekswill 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 usenowtime specifiers withcount. In the example we will set command to run after 15 minutes.

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

$ at now + 15 minutes

Schedule Job With Relative Time
安排相对时间的工作

We can see from screenshot that the command is set to run at21:31which is after 15 minutes from now. We can see that this job is numbered2

从屏幕截图中我们可以看到,该命令设置为从现在开始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 withatqcommand.

在繁忙的系统中,可能会有很多计划的作业。 列出它们可以使用atq命令完成。

$ atq

View All The Schedules Jobs
查看所有计划作业

We can see that there is only one job in the list. This job is numbered as2. This job will e run atThu Mar 9 21:31:00. The job is created by userismail

我们可以看到列表中只有一项工作。 这项工作被编号为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 withatq. We will provide job ID to theatrmcommand like below. We will remove job ID2.

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

$ atrm 2

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 usebatchcommand to run commands if load average is less than1.5. In the example we will runecho "Run reports"

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

$ batch

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-foption and the command file name to use this feature. In the example we will read commands file namedmyjobs.txtand run them after 2 days.

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

$ at -f myjobs.txt now + 2 days

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.allowis used to set allowed users

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

at.denyis used to set denied users

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

翻译自: /linux-scheduling-commands-atq-atrm-batch-examples/

atq1

如果觉得《atq1_使用at atq atrm和batchLinux调度命令示例》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。