例
次に、autocommand コマンドを使用して、ユーザがデフォルトの VTY セッションにログインしたときに show ip interface brief コマンドを自動的に実行する例を示します。
RP/0/RSP0/CPU0:router# configure terminal
RP/0/RSP0/CPU0:router(config)# line default
RP/0/RSP0/CPU0:router(config-line)# autocommand show ip interface brief
RP/0/RSP0/CPU0:router(config-line)# end
Uncommitted changes found, commit them before exiting(yes/no/cancel)? [cancel]:yes
RP/0/RSP0/CPU0:router# exit
<Your 'TELNET' connection has terminated>
次に、ユーザが VTY セッションにログインしたときに show ip interface brief コマンドを自動的に実行する例を示します。
User Access Verification
Username: lab
Password:
Executing Autocommand 'show ip interface brief'
RP/0/RSP0/CPU0:router# show ip interface brief
Interface IP-Address Status Protocol
MgmtEth0/RP0/CPU0/0 172.16.0.0 Up Up
POS0/0/0/0 unassigned Up Up
POS0/0/0/1 unassigned Up Up
POS0/0/0/2 unassigned Up Up
POS0/0/0/3 unassigned Up Up
POS0/3/0/0 unassigned Up Up
POS0/3/0/1 unassigned Up Up
POS0/3/0/2 unassigned Up Up
POS0/3/0/3 unassigned Up Up
次に、autocommand コマンドの no 形式を使用してこの機能をディセーブルにする例を示します。 この例では、show ip interface brief コマンドに対する autocommand をディセーブルにしています。 ユーザがログアウトしてから再びログインしたとき、autocommand コマンドは実行されません。
RP/0/RSP0/CPU0:router# configure terminal
RP/0/RSP0/CPU0:router(config)# line default
RP/0/RSP0/CPU0:router(config-line)# no autocommand ?
LINE Appropriate EXEC command
RP/0/RSP0/CPU0:router(config-line)# no autocommand show ip interface brief
RP/0/RSP0/CPU0:router(config-line)# end
Uncommitted changes found, commit them before exiting(yes/no/cancel)? [cancel]:yes
RP/0/RSP0/CPU0:router# exit
<Your 'TELNET' connection has terminated>
User Access Verification
Username: lab
Password:
RP/0/RSP0/CPU0:router#
次に、autocommand コマンドでコマンド エイリアスを使用して、ユーザがデフォルトの VTY セッションにログインしたときに複数のコマンドを実行する例を示します。 この例では、「test」というエイリアスを作成し、show ip interface brief コマンドと show users コマンドを組み込んでいます。 その後、autocommand 機能を使用して、ユーザが VTY 端末にログインしたときに「test」エイリアスを実行します。
RP/0/RSP0/CPU0:router# configure terminal
RP/0/RSP0/CPU0:router(config)# alias test show ip interface brief; show users
RP/0/RSP0/CPU0:router(config)# line default
RP/0/RSP0/CPU0:router(config-line)# autocommand test
RP/0/RSP0/CPU0:router(config-line)# end
Uncommitted changes found, commit them before exiting(yes/no/cancel)? [cancel]:yes
RP/0/RSP0/CPU0:router# exit
<Your 'TELNET' connection has terminated>
User Access Verification
Username: lab
Password:
Executing Autocommand 'test'
RP/0/RSP0/CPU0:router# test
RP/0/RSP0/CPU0:router# show ip interface brief
Interface IP-Address Status Protocol
MgmtEth0/RP0/CPU0/0 172.16.0.0 Up Up
POS0/0/0/0 unassigned Up Up
POS0/0/0/1 unassigned Up Up
POS0/0/0/2 unassigned Up Up
POS0/0/0/3 unassigned Up Up
POS0/3/0/0 unassigned Up Up
POS0/3/0/1 unassigned Up Up
POS0/3/0/2 unassigned Up Up
POS0/3/0/3 unassigned Up Up
RP/0/RSP0/CPU0:router# show users
Line User Service Conns Idle Location
* vty0 lab telnet 0 00:00:00 172.16.0.0