Execute CLI Commands Using an Event Policy
To execute a CLI command on occurrence of an event, use the following configuration:
1
|
[edit]
|
2
|
user@host# show event-options
|
3
|
policy <policy-name> {
|
4
|
events <event-name>;
|
5
|
then {
|
6
|
execute-commands {
|
7
|
commands {
|
8
|
"show version";
|
9
|
}
|
10
|
output-filename cmd_output;
|
11
|
destination test_dest;
|
12
|
}
|
13
|
}
|
14
|
}
|
15
|
destinations {
|
16
|
test_dest {
|
17
|
archive-sites {
|
18
|
/var/tmp;
|
19
|
}
|
20
|
}
|
21
|
}
|
22
|
|
23
|
[edit]
|
24
|
user@host#
|
As described in the previous configuration example, when a specified event occurs in the system, the policy is executed and a CLI command mentioned in the policy executes (in this example, "show version").
The output of the command is saved in the file 'cmd_output' and transferred to a specified destination directory (in this example, "/var/tmp").
When the output file is written to the destination directory, the Junos OS system name and timestamp are appended to the file name.