-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.txt
69 lines (67 loc) · 2.1 KB
/
script.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
!
conf t
no event manager applet ReNTP
event manager applet ReNTP
event none
!event timer cron name 6HSaturday cron-entry "0 6 * * 6"
action 001 syslog msg "Start check NTP Status"
action 002 cli command "enable"
action 004 cli command "term length 0"
action 010 set i "0"
action 011 cli command "show ntp associations"
action 012 set cliass "$_cli_result"
action 013 foreach line "$cliass" "\n"
action 014 regexp "INIT" "$line"
action 015 if $_regexp_result eq "1"
action 016 increment i
action 017 end
action 018 end
action 019 if $i eq "0" goto 098
action 020 syslog msg "Fount $i bad ntp, continue"
!
action 030 set i "0"
action 031 cli command "show ntp conf"
action 032 set cliconf "$_cli_result"
action 033 foreach line "$cliconf" "\n"
action 034 regexp "ntp\s(server|peer)\s(.*)" "$line" match nctype ncip
action 035 if $_regexp_result eq "1"
action 036 set tmpstr "$match"
action 037 string trim "$tmpstr"
action 038 append ntpconfs "ntp $nctype $ncip\n"
action 039 increment i
action 040 end
action 041 end
action 042 if $i eq "0" goto 098
!action 043 syslog msg "$ntpconfs"
!
action 050 set i "0"
action 051 foreach line "$cliass" "\n"
action 052 regexp "^[ -~+*][ ~+]([0-9]+.[0-9]+.[0-9]+.[0-9]+)\s+(.INIT.|[0-9]+.[0-9]+.[0-9]+.[0-9]+)" "$line" match gr1 gr2
action 053 if $_regexp_result eq "1"
action 054 increment i
!action 055 syslog msg "ID: $i, GR1: $gr1, GR2: $gr2"
!
action 060 regexp ".INIT." "$gr2"
action 061 if $_regexp_result eq "1"
action 062 set j "0"
!action 063 syslog msg "Found INIT, i=$i, j=$j"
action 064 foreach cnfine "$ntpconfs" "\n"
action 065 increment j
action 066 if $i eq "$j"
!action 067 syslog msg "BC: $cnfine, i=$i, j=$j"
action 068 cli command "conf t"
action 069 cli command "no $cnfine"
action 070 cli command "$cnfine"
action 071 cli command "end"
action 072 break
action 073 end
!action 074 syslog msg "J:$j, I:$i cnfine:$cnfine"
action 075 end
action 076 end
!
action 080 end
action 081 end
action 098 syslog msg "End Script"
action 099 exit
exit
!