最佳答案
可以,配置job认证就行
如图1所示,路由器Router连接两台主机,现要求:对Router配置定时执行任务功能,使得在星期一到星期五的上午八点到下午十八点开启GigabitEthernet1/0/1和GigabitEthernet1/0/2,其它时间关闭端口。
本举例是在R6728版本上进行配置和验证的。
· 通过command指定的命令行必须是设备上可成功执行的命令行;否则,命令行不能自动被执行。
· 通过command指定的命令行不能包括telnet、ftp、ssh2和monitor process命令。
· 在配置定时任务前,需查看系统时间是否正确。如果系统时间不正确的话,可以通过配置NTP功能或者clock命令进行修改,保证设备获得准确的时间。
(1) 配置关闭和开启接口的工作任务
# 创建名称为shutdown-GigabitEthernet1/0/1的工作任务并进入Job视图。
[Router] scheduler job shutdown-GigabitEthernet1/0/1
# 为Job分配命令,以进入系统视图。
[Router-job-shutdown-GigabitEthernet1/0/1] command 1 system-view
# 为Job分配命令,以进入GigabitEthernet1/0/1接口视图。
[Router-job-shutdown-GigabitEthernet1/0/1] command 2 interface gigabitethernet 1/0/1
# 为Job分配命令,以执行关闭GigabitEthernet1/0/1接口。
[Router-job-shutdown-GigabitEthernet1/0/1] command 3 shutdown
[Router-job-shutdown-GigabitEthernet1/0/1] quit
# 创建名称为shutdown-GigabitEthernet1/0/2的工作任务并进入Job视图。
[Router] scheduler job shutdown-GigabitEthernet1/0/2
# 为Job分配命令,以进入系统视图。
[Router-job-shutdown-GigabitEthernet1/0/2] command 1 system-view
# 为Job分配命令,以进入GigabitEthernet1/0/2接口视图。
[Router-job-shutdown-GigabitEthernet1/0/2] command 2 interface gigabitethernet 1/0/2
# 为Job分配命令,以执行关闭GigabitEthernet1/0/2接口。
[Router-job-shutdown-GigabitEthernet1/0/2] command 3 shutdown
[Router-job-shutdown-GigabitEthernet1/0/2] quit
# 创建名称为start-GigabitEthernet1/0/1的工作任务并进入Job视图。
[Router] scheduler job start-GigabitEthernet1/0/1
# 为Job分配命令,以进入系统视图。
[Router-job-start-GigabitEthernet1/0/1] command 1 system-view
# 为Job分配命令,以进入GigabitEthernet1/0/1接口视图。
[Router-job-start-GigabitEthernet1/0/1] command 2 interface gigabitethernet 1/0/1
# 为Job分配命令,以执行开启GigabitEthernet1/0/1接口。
[Router-job-start-GigabitEthernet1/0/1] command 3 undo shutdown
[Router-job-start-GigabitEthernet1/0/1] quit
# 创建名称为start-GigabitEthernet1/0/2的工作任务并进入Job视图。
[Router] scheduler job start-GigabitEthernet1/0/2
# 为Job分配命令,以进入系统视图。
[Router-job-start-GigabitEthernet1/0/2] command 1 system-view
# 为Job分配命令,以进入GigabitEthernet1/0/2接口视图。
[Router-job-start-GigabitEthernet1/0/2] command 2 interface gigabitethernet 1/0/2
# 为Job分配命令,以执行开启GigabitEthernet1/0/2接口。
[Router-job-start-GigabitEthernet1/0/2] command 3 undo shutdown
[Router-job-start-GigabitEthernet1/0/2] quit
(2) 配置定时执行任务
# 创建名为connect-host1/host2的Schedule,并进入Schedule视图。
[Router] scheduler schedule connect-host1/host2
# 为Schedule分配名为start-GigabitEthernet1/0/1的job。
[Router-schedule-connect-host1/host2] job start-GigabitEthernet1/0/1
# 为Schedule分配名为start-GigabitEthernet1/0/2的job。
[Router-schedule-connect-host1/host2] job start-GigabitEthernet1/0/2
# 为Schedule配置循环执行的时间,在星期一到星期五的上午8点开启GigabitEthernet1/0/1和GigabitEthernet1/0/2接口。
[Router-schedule-connect-host1/host2] time repeating at 08:00 week-day Mon Tue Wed Thu Fri
[Router-schedule-connect-host1/host2] quit
# 创建名为unconnect-host1/host2的Schedule,并进入Schedule视图。
[Router] scheduler schedule unconnect-host1/host2
# 为Schedule分配名为shutdown-GigabitEthernet1/0/1的job。
[Router-schedule-unconnect-host1/host2] job shutdown-GigabitEthernet1/0/1
# 为Schedule分配名为shutdown-GigabitEthernet1/0/2的job。
[Router-schedule-unconnect-host1/host2] job shutdown-GigabitEthernet1/0/2
# 为Schedule配置循环执行的时间,在星期一到星期五的下午18点关闭GigabitEthernet1/0/1和GigabitEthernet1/0/2接口。
[Router-schedule-unconnect-host1/host2] time repeating at 18:00 week-day Mon Tue Wed Thu Fri
[Router-schedule-unconnect-host1/host2] quit
# 使用display scheduler job命令显示Job的配置信息。
<Router> display scheduler job
Job name: shutdown-GigabitEthernet1/0/1
system-view
interface gigabitethernet1/0/1
shutdown
Job name: shutdown-GigabitEthernet1/0/2
system-view
interface gigabitethernet1/0/2
shutdown
Job name: start-GigabitEthernet1/0/1
system-view
interface gigabitethernet1/0/1
undo shutdown
Job name: start-GigabitEthernet1/0/2
system-view
interface gigabitethernet1/0/2
undo shutdown
# 使用display scheduler schedule命令显示定时任务的运行信息。
<Router> display scheduler schedule
Schedule name : connect-host1/host2
Schedule type : Run on every Mon Tue Wed Thu Fri at 08:00:00
Start time : Thu Nov 14 08:00:00 2013
Last execution time : Yet to be executed
-----------------------------------------------------------------------
Job name Last execution status
start-GigabitEthernet1/0/1 -NA-
start-GigabitEthernet1/0/2 -NA-
Schedule name : unconnect-host1/host2
Schedule type : Run on every Mon Tue Wed Thu Fri at 18:00:00
Start time : Wed Nov 13 18:00:00 2013
Last execution time : Yet to be executed
-----------------------------------------------------------------------
Job name Last execution status
shutdown-GigabitEthernet1/0/1 -NA-
shutdown-GigabitEthernet1/0/2 -NA-
# 在上午7:59时,使用display ip interface brief命令查看三层接口状态。
[Router] display ip interface brief
*down: administratively down
(s): spoofing (l): loopback
Interface Physical Protocol IP Address Description
Ana3/0 down down -- --
Aux0 up down -- --
GE0/0 up up 192.168.100.67 --
GE1/0/1 *down down -- --
GE1/0/2 *down down -- --
# 当到上午8:00时候,设备有如下日志信息显示。
%Apr 22 08:00:10:245 2014 Router IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet1/0/1 changed to up.
%Apr 22 08:00:10:245 2014 Router IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet1/0/1 changed to up.
%Apr 22 08:00:10:250 2014 Router IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet1/0/2 changed to up.
%Apr 22 08:00:10:250 2014 Router IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet1/0/2 changed to up.
# 在上午8:00时,使用display ip interface brief命令查看三层接口状态。
[Router] display ip interface brief
*down: administratively down
(s): spoofing (l): loopback
Interface Physical Protocol IP Address Description
Ana3/0 down down -- --
Aux0 up down -- --
GE0/0 up up 192.168.100.67 --
GE1/0/1 up up -- --
GE1/0/2 up up -- --
# 当到下午18:00时候,设备有如下日志信息显示。
%Apr 22 18:00:06:250 2014 Router IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet1/0/1 changed to down.
%Apr 22 18:00:06:250 2014 Router IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet1/0/1 changed to down.
%Apr 22 18:00:06:256 2014 Router IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet1/0/2 changed to down.
%Apr 22 18:00:06:256 2014 Router IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet1/0/2 changed to down.
# 在下午18:00时,使用display ip interface brief命令查看三层接口状态。
[Router] display ip interface brief
*down: administratively down
(s): spoofing (l): loopback
Interface Physical Protocol IP Address Description
Ana3/0 down down -- --
Aux0 up down -- --
GE0/0 up up 192.168.100.67 --
GE1/0/1 *down down -- --
GE1/0/2 *down down -- --
#
scheduler job shutdown-GigabitEthernet1/0/1
command 1 system-view
command 2 interface gigabitethernet1/0/1
command 3 shutdown
#
scheduler job shutdown-GigabitEthernet1/0/2
command 1 system-view
command 2 interface gigabitethernet1/0/2
command 3 shutdown
#
scheduler job start-GigabitEthernet1/0/1
command 1 system-view
command 2 interface gigabitethernet1/0/1
command 3 undo shutdown
#
scheduler job start-GigabitEthernet1/0/2
command 1 system-view
command 2 interface gigabitethernet1/0/2
command 3 undo shutdown
#
scheduler schedule connect-host1/host2
job start-GigabitEthernet1/0/1
job start-GigabitEthernet1/0/2
time repeating at 08:00 week-day Mon Tue Wed Thu Fri
#
scheduler schedule unconnect-host1/host2
job shutdown-GigabitEthernet1/0/1
job shutdown-GigabitEthernet1/0/2
time repeating at 18:00 week-day Mon Tue Wed Thu Fri
#
(0)
您好,参考案例
对Device进行配置,在星期一到星期五的上午八点到下午十八点开启GigabitEthernet1/0/1和GigabitEthernet1/0/2,其它时间关闭端口,以便起到有效节能的作用。
图1-1 定时执行任务典型配置举例组网图
# 进入系统视图。
<Sysname> system-view
# 创建关闭GigabitEthernet1/0/1的Job。
[Sysname] scheduler job shutdown-GigabitEthernet1/0/1
[Sysname-job-shutdown-GigabitEthernet1/0/1] command 1 system-view
[Sysname-job-shutdown-GigabitEthernet1/0/1] command 2 interface gigabitethernet 1/0/1
[Sysname-job-shutdown-GigabitEthernet1/0/1] command 3 shutdown
[Sysname-job-shutdown-GigabitEthernet1/0/1] quit
# 创建开启GigabitEthernet1/0/1的Job。
[Sysname] scheduler job start-GigabitEthernet1/0/1
[Sysname-job-start-GigabitEthernet1/0/1] command 1 system-view
[Sysname-job-start-GigabitEthernet1/0/1] command 2 interface gigabitethernet 1/0/1
[Sysname-job-start-GigabitEthernet1/0/1] command 3 undo shutdown
[Sysname-job-start-GigabitEthernet1/0/1] quit
# 创建关闭GigabitEthernet1/0/2的Job。
[Sysname] scheduler job shutdown-GigabitEthernet1/0/2
[Sysname-job-shutdown-GigabitEthernet1/0/2] command 1 system-view
[Sysname-job-shutdown-GigabitEthernet1/0/2] command 2 interface gigabitethernet 1/0/2
[Sysname-job-shutdown-GigabitEthernet1/0/2] command 3 shutdown
[Sysname-job-shutdown-GigabitEthernet1/0/2] quit
# 创建开启GigabitEthernet1/0/2的Job。
[Sysname] scheduler job start-GigabitEthernet1/0/2
[Sysname-job-start-GigabitEthernet1/0/2] command 1 system-view
[Sysname-job-start-GigabitEthernet1/0/2] command 2 interface gigabitethernet 1/0/2
[Sysname-job-start-GigabitEthernet1/0/2] command 3 undo shutdown
[Sysname-job-start-GigabitEthernet1/0/2] quit
# 配置定时执行任务,使Device在星期一到星期五的上午八点开启pc1、pc2对应的以太网端口。
[Sysname] scheduler schedule START-pc1/pc2
[Sysname-schedule-START-pc1/pc2] job start-GigabitEthernet1/0/1
[Sysname-schedule-START-pc1/pc2] job start-GigabitEthernet1/0/2
[Sysname-schedule-START-pc1/pc2] time repeating at 8:00 week-day mon tue wed thu fri
[Sysname-schedule-START-pc1/pc2] quit
# 配置定时执行任务,使Device在星期一到星期五的下午十八点关闭pc1、pc2对应的以太网端口。
[Sysname] scheduler schedule STOP-pc1/pc2
[Sysname-schedule-STOP-pc1/pc2] job shutdown-GigabitEthernet1/0/1
[Sysname-schedule-STOP-pc1/pc2] job shutdown-GigabitEthernet1/0/2
[Sysname-schedule-STOP-pc1/pc2] time repeating at 18:00 week-day mon tue wed thu fri
[Sysname-schedule-STOP-pc1/pc2] quit
(0)
暂无评论
定时执行任务有两种类型:一次性执行方式和循环执行方式。两种方式都支持在同一任务中执行多条命令。一次性执行的配置任务不能保存到配置文件,设备重启后该任务将取消。循环执行的配置任务能保存到配置文件,等下次时间到达,任务将自动执行。
· 如果需要分配的命令(假设为A)是用户视图下的命令,则直接使用command命令分配即可,比如:command 1 display interface;如果需要分配的命令(假设为A)是非用户视图下的命令,则必须先分配进入A所在视图的命令(指定较小的id值),再分配A。比如:要使用Job定时执行shutdown命令,则需执行三次command命令,分别分配system-view、interface、shutdown命令,且各command命令的id值逐渐增大。
· 通过command指定的命令行必须是设备上可成功执行的命令行,由用户保证配置的正确性。否则,命令行不能自动被执行。
· 通过command指定的命令行不能包括telnet、ftp、ssh2和monitor process。
· 定时执行任务时,设备不会与用户交互信息。当需要用户交互确认时,系统将自动输入“Y”或“Yes”;当需要用户交互输入字符信息时,系统将自动输入缺省字符串,没有缺省字符串的将自动输入空字符串。
· 系统将在后台定时执行任务,不显示任何输出信息(log、trap、debug等系统信息除外)。
为Job分配命令 | 缺省情况下,没有为Job分配命令 多次执行该命令可以为Job分配多条命令,命令的执行顺序由id参数的大小决定,数值小的先执行 | |
退回系统视图 | quit | - |
为Schedule分配Job | 缺省情况下,没有为Schedule分配Job 多次执行该命令可以为Schedule分配多个Job,各个Job之间并发执行 | |
配置执行Schedule的定时任务时使用的用户角色 | 缺省情况下,Schedule执行定时任务时使用的用户角色,为创建该Schedule的用户的用户角色 多次执行本命令可给Schedule配置多个用户角色,系统会使用这些用户角色权限的并集去执行Schedule。同一个Schedule最多可以配置64个用户角色 | |
缺省情况下,没有为Schedule配置执行时间 使用该方式配置定时执行功能后,即便执行clock datetime、clock summer-time或clock timezone命令调整了系统时间,也不会影响该任务的配置 | ||
为Schedule配置执行时间 | time once at time [ month-date month-day | week-day week-day&<1-7> ] | |
为Schedule配置循环执行时间 | time repeating at time [ month-date [ month-day | last ] | week-day week-day&<1-7> ] | |
为Schedule配置循环执行周期 | time repeating [ at time [date ] ] interval interval |
对Device进行配置,在星期一到星期五的上午八点到下午十八点开启GigabitEthernet1/0/1和GigabitEthernet1/0/2,其它时间关闭端口,以便起到有效节能的作用。
# 进入系统视图。
# 创建关闭GigabitEthernet1/0/1的Job。
[Sysname] scheduler job shutdown-GigabitEthernet1/0/1
[Sysname-job-shutdown-GigabitEthernet1/0/1] command 1 system-view
[Sysname-job-shutdown-GigabitEthernet1/0/1] command 2 interface gigabitethernet 1/0/1
[Sysname-job-shutdown-GigabitEthernet1/0/1] command 3 shutdown
[Sysname-job-shutdown-GigabitEthernet1/0/1] quit
# 创建开启GigabitEthernet1/0/1的Job。
[Sysname] scheduler job start-GigabitEthernet1/0/1
[Sysname-job-start-GigabitEthernet1/0/1] command 1 system-view
[Sysname-job-start-GigabitEthernet1/0/1] command 2 interface gigabitethernet 1/0/1
[Sysname-job-start-GigabitEthernet1/0/1] command 3 undo shutdown
[Sysname-job-start-GigabitEthernet1/0/1] quit
# 创建关闭GigabitEthernet1/0/2的Job。
[Sysname] scheduler job shutdown-GigabitEthernet1/0/2
[Sysname-job-shutdown-GigabitEthernet1/0/2] command 1 system-view
[Sysname-job-shutdown-GigabitEthernet1/0/2] command 2 interface gigabitethernet 1/0/2
[Sysname-job-shutdown-GigabitEthernet1/0/2] command 3 shutdown
[Sysname-job-shutdown-GigabitEthernet1/0/2] quit
# 创建开启GigabitEthernet1/0/2的Job。
[Sysname] scheduler job start-GigabitEthernet1/0/2
[Sysname-job-start-GigabitEthernet1/0/2] command 1 system-view
[Sysname-job-start-GigabitEthernet1/0/2] command 2 interface gigabitethernet 1/0/2
[Sysname-job-start-GigabitEthernet1/0/2] command 3 undo shutdown
[Sysname-job-start-GigabitEthernet1/0/2] quit
# 配置定时执行任务,使Device在星期一到星期五的上午八点开启pc1、pc2对应的以太网端口。
[Sysname] scheduler schedule START-pc1/pc2
[Sysname-schedule-START-pc1/pc2] job start-GigabitEthernet1/0/1
[Sysname-schedule-START-pc1/pc2] job start-GigabitEthernet1/0/2
[Sysname-schedule-START-pc1/pc2] time repeating at 8:00 week-day mon tue wed thu fri
[Sysname-schedule-START-pc1/pc2] quit
# 配置定时执行任务,使Device在星期一到星期五的下午十八点关闭pc1、pc2对应的以太网端口。
[Sysname] scheduler schedule STOP-pc1/pc2
[Sysname-schedule-STOP-pc1/pc2] job shutdown-GigabitEthernet1/0/1
[Sysname-schedule-STOP-pc1/pc2] job shutdown-GigabitEthernet1/0/2
[Sysname-schedule-STOP-pc1/pc2] time repeating at 18:00 week-day mon tue wed thu fri
[Sysname-schedule-STOP-pc1/pc2] quit
# 显示Job的配置信息。
[Sysname] display scheduler job
Job name: shutdown-GigabitEthernet1/0/1
system-view
interface gigabitethernet 1/0/1
shutdown
Job name: shutdown-GigabitEthernet1/0/2
system-view
interface gigabitethernet 1/0/2
shutdown
Job name: start-GigabitEthernet1/0/1
system-view
interface GigabitEthernet 1/0/1
undo shutdown
Job name: start-GigabitEthernet1/0/2
system-view
interface gigabitethernet 1/0/2
undo shutdown
# 显示定时任务的运行信息。
[Sysname] display scheduler schedule
Schedule name : START-pc1/pc2
Schedule type : Run on every Mon Tue Wed Thu Fri at 08:00:00
Start time : Wed Sep 28 08:00:00 2011
Last execution time : Wed Sep 28 08:00:00 2011
Last completion time : Wed Sep 28 08:00:03 2011
Execution counts : 1
-----------------------------------------------------------------------
Job name Last execution status
start-GigabitEthernet1/0/1 Successful
start-GigabitEthernet1/0/2 Successful
Schedule name : STOP-pc1/pc2
Schedule type : Run on every Mon Tue Wed Thu Fri at 18:00:00
Start time : Wed Sep 28 18:00:00 2011
Last execution time : Wed Sep 28 18:00:00 2011
Last completion time : Wed Sep 28 18:00:01 2011
Execution counts : 1
-----------------------------------------------------------------------
Job name Last execution status
shutdown-GigabitEthernet1/0/1 Successful
shutdown-GigabitEthernet1/0/2 Successful
# 显示Job运行的输出信息。
[Sysname] display scheduler logfile
Job name : start-GigabitEthernet1/0/1
Schedule name : START-pc1/pc2
Execution time : Wed Sep 28 08:00:00 2011
Completion time : Wed Sep 28 08:00:02 2011
--------------------------------- Job output -----------------------------------
<Sysname>system-view
System View: return to User View with Ctrl+Z.
[Sysname]interface gigabitethernet 1/0/1
[Sysname-GigabitEthernet1/0/1]undo shutdown
Job name : start-GigabitEthernet1/0/2
Schedule name : START-pc1/pc2
Execution time : Wed Sep 28 08:00:00 2011
Completion time : Wed Sep 28 08:00:02 2011
--------------------------------- Job output -----------------------------------
<Sysname>system-view
System View: return to User View with Ctrl+Z.
[Sysname]interface gigabitethernet 1/0/2.
[Sysname-GigabitEthernet1/0/2]undo shutdown
Job name : shutdown-GigabitEthernet1/0/1
Schedule name : STOP-pc1/pc2
Execution time : Wed Sep 28 18:00:00 2011
Completion time : Wed Sep 28 18:00:01 2011
--------------------------------- Job output -----------------------------------
<Sysname>system-view
System View: return to User View with Ctrl+Z.
[Sysname]interface gigabitethernet 1/0/1
[Sysname-GigabitEthernet1/0/1]shutdown
Job name : shutdown-GigabitEthernet1/0/2
Schedule name : STOP-pc1/pc2
Execution time : Wed Sep 28 18:00:00 2011
Completion time : Wed Sep 28 18:00:01 2011
--------------------------------- Job output -----------------------------------
<Sysname>system-view
System View: return to User View with Ctrl+Z.
[Sysname]interface gigabitethernet 1/0/2
[Sysname-GigabitEthernet1/0/2]shutdown
(0)
暂无评论
亲~登录后才可以操作哦!
确定你的邮箱还未认证,请认证邮箱或绑定手机后进行当前操作
举报
×
侵犯我的权益
×
侵犯了我企业的权益
×
抄袭了我的内容
×
原文链接或出处
诽谤我
×
对根叔社区有害的内容
×
不规范转载
×
举报说明
暂无评论