Skip to Content
Arista Warrior,第二版
book

Arista Warrior,第二版

by Gary A. Donahue
May 2025
Intermediate to advanced
572 pages
8h 39m
Chinese
O'Reilly Media, Inc.
Book available
Content preview from Arista Warrior,第二版

第24章 日程安排 调度程序

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

我当时在一个数据中心工作,正在构建一个 Arista 网络,我决定要自动执行一个每五分钟运行一次的命令。我知道这些超酷的 Arista 交换机运行 Linux,于是我打开了 bash,开始捣鼓cron。我无法让它正常工作,感到很沮丧,于是打电话给我的 Arista 销售工程师,他问:"为什么不直接使用计划表呢?

Schedule 是 EOS 4.5 版开始使用的一项功能,它允许定期调度命令。这项功能最酷的地方在于,它完全可以通过命令行界面(CLI)进行配置,因此你不需要花时间对着cron 发牢骚。在本章中,我们将介绍这一强大的工具。

schedule 命令是我们在本章中要做的所有事情的基础。该命令使用简单,问号(?)和制表符补全可以让你获得关于其功能的大部分信息:

Arista(config)#schedule ?
  WORD    Scheduled job name
  config  Set CLI scheduler configuration parameters

从 EOS 4.21.1F 开始,唯一的配置选项是max-concurrent-jobsprepend-hostname-logfile ,前者可以从 1 到 4 设置,默认为 1,后者的作用和听起来一样,现在是默认行为:

Arista(config)#schedule config max-concurrent-jobs ?
  <1-4>  Maximum number of concurrent jobs

要创建计划任务,首先必须为任务指定一个名称。因为我是作者,而且我爱我的女儿,所以我将使用科琳这个名字来命名我的工作。在我编写第一版《Arista Warrior》的黑暗时代,计划表还有一些很酷的新选项:

Arista(config)#schedule Colleen ?
  at        Set the start time of the schedule
  interval  Set interval for CLI command execution
  now       Set the start time of the schedule to now

时间间隔是指作业每次迭代之间等待的时间(以分钟为单位)。如果希望作业每五分钟运行一次,间隔时间应为5 。在 4.21.1F 版中,可接受的值范围为21440

Arista(config)#schedule Colleen interval ?
  <2-1440>  Interval in minutes for CLI command execution

请注意,与早期版本相比,这是一个重大变化,早期版本的范围是11440 。虽然这看起来并不重要,但这一变化是因为现在的间隔时间至少需要是超时值的两倍,超时值默认为 30 秒:

Arista(config)#schedule Colleen interval 5 timeout ?
  <1-480>  Timeout in minutes for CLI command execution

事实上,如果将时间间隔设置为不大于超时的值,计划将不会被接受:

Arista(config)#schedule Colleen interval 5 max-log-files 5 command sho ver ! Schedule a command starting in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Practical Guide to Fedora™ and Red Hat® Enterprise Linux®, Seventh Edition

A Practical Guide to Fedora™ and Red Hat® Enterprise Linux®, Seventh Edition

Mark G. Sobell

Publisher Resources

ISBN: 9798341658967