Post by heasleyPost by PaweÅ RzepaHi,
Any help? I've digged into this a little and found that .cloginrc is
interpreted by expect. I'm not very familiar with expect, tried some
regexps with braces, escaped braces etc and no success. Is it impossible
to use regexp in this context?
no; if it were, the manpage would have read regex, not glob. regex would
be useful; though i'm not sure how to implement it, since glob and regex
are not complatible. perhaps a global knob in cloginrc that switches the
format to regex? or an regex-specific version of the 'add' function and
search regexes before globs?
Per Olaf, ideas?
Just replace "string match" with "regexp" will make a big format change in cloginrc.
Think it's just to look for $ ( ) ^ | + or "\." ("([$)(^|+]|\\\.)+" in regexp)
to determining if it is regexp or not. Possible it will give some false match
and cloginrc need to be written more strict.
...
Post by heasleyPost by PaweÅ RzepaPost by PaweÅ Rzepaadd user {192.168.1.*|192.168.2.5|*-core-*} {user1}
add password {192.168.1.*|192.168.2.5|*-core-*} {pass1}
add user {10.1.2.3|10.1.5.*} {user2}
...
Just not that simple when you say regexp.
add user {^(192\.168\.1\..*|192\.168\.2\.5|.*-core-.*)$} {user1}
".*" for numbers? Why not "[0-9]+".
add user {^(192\.168\.1\.[0-9]+|192\.168\.2\.5|.*-core-.*)$} {user1}
Is this a possible way?
cloginrc in my test.
------cloginrc---------------------------------
add password {sw1.aaa.domain.se} x x
add method {10\.10\.1\.1|10\.10\.3\.[0-9]+|sw1\.aaa\.domain\.se} ssh
add password {10\.10\.1\.1|10\.10\.4\.[0-9]+} x x
add identity {^(10\.10\.1\.1|10\.10\.3\.[0-9]+|sw1\.aaa\.domain\.se)$} /home/rancid/.ssh/ssh_key
add autoenable {10\.10\.1\.1|10\.10\.3\.[0-9]+|sw1\.aaa\.domain\.se} 1
add password * y y
-----------------------------------------------
$ ./hlogin +debug_rc +debug_rc -c "show term" -f cloginrc -banner 10.10.3.74
10.10.3.74
Match regexp: 10.10.3.74 autoenable {10\.10\.1\.1|10\.10\.3\.[0-9]+|sw1\.aaa\.domain\.se} 1
No match : 10.10.3.74 password sw1.aaa.domain.se x x
No match : 10.10.3.74 password {10\.10\.1\.1|10\.10\.4\.[0-9]+} x x
Match : 10.10.3.74 password * y y
Match regexp: 10.10.3.74 identity {^(10\.10\.1\.1|10\.10\.3\.[0-9]+|sw1\.aaa\.domain\.se)$} /home/rancid/.ssh/ssh_key
Match regexp: 10.10.3.74 method {10\.10\.1\.1|10\.10\.3\.[0-9]+|sw1\.aaa\.domain\.se} ssh
spawn hpuifilter -- ssh -i /home/rancid/.ssh/ssh_key -c 3des -x -l rancid 10.10.3.74
switch.aaa.domain.s# no page
switch.aaa.domain.s# show term
Terminal width: 132 length: 24
switch.aaa.domain.s#logout
Do you want to log out [y/n]? y
Connection to 10.10.3.74 closed.
Have tested same update on clogin and hlogin 2.3.8
----------------------------------------
*** clogin 2014-02-21 11:03:17.903550570 +0100
--- clogin_new 2014-02-23 08:36:49.088227859 +0100
***************
*** 54,59 ****
--- 54,60 ----
# Usage line
set usage "Usage: $argv0 \[-dSV\] \[-autoenable\] \[-noenable\] \[-c command\] \
+ \[+debug_rc\] \
\[-Evar=x\] \[-e enable-password\] \[-f cloginrc-file\] \[-p user-password\] \
\[-r passphrase\] \[-s script-file\] \[-t timeout\] \[-u username\] \
\[-v vty-password\] \[-w enable-username\] \[-x command-file\] \
***************
*** 76,81 ****
--- 77,84 ----
# tracks if we receive them on the command line.
set do_passwd 1
set do_enapasswd 1
+ # debug matching cloginrc file
+ set debug_rc 0
# Save config, if prompted
set do_saveconfig 0
# Sometimes routers take awhile to answer (the default is 10 sec)
***************
*** 112,117 ****
--- 115,124 ----
# Expect debug mode
-d* {
exp_internal 1
+ # debug matching cloginrc file
+ # option twice, also show "No match"
+ } +debug_rc* {
+ set debug_rc [expr {$debug_rc + 1}]
# Username
} -u* {
if {! [regexp .\[uU\](.+) $arg ignore user]} {
***************
*** 282,292 ****
proc find {var router} {
upvar int_$var list
if { [info exists list] } {
foreach line $list {
! if { [string match [lindex $line 0] $router] } {
! return [lrange $line 1 end]
}
}
}
return {}
--- 289,311 ----
proc find {var router} {
upvar int_$var list
+ global debug_rc
+ set match_regexp 0
if { [info exists list] } {
foreach line $list {
! if { [ regexp {([$)(^|+]|\\\.)+} [lindex $line 0] ] } {
! catch { set match_regexp [regexp [lindex $line 0] $router] } reason
! if { $match_regexp != 0 } {
! if { $debug_rc } {send_user "Match regexp: $router $var $line\n"}
! return [lrange $line 1 end]
! }
! } else {
! if { [string match [lindex $line 0] $router] } {
! if { $debug_rc } { send_user "Match : $router $var $line\n" }
! return [lrange $line 1 end]
! }
}
+ if { $debug_rc >= 2 } {send_user "No match : $router $var $line\n"}
}
}
return {}
-----------------------------------------
Post by heasleyPost by PaweÅ RzepaRegards,
Pawel Rzepa
Post by PaweÅ RzepaHi,
When I log into my devices to get configuration with rancid I must use
two different users for two different groups of devices. I know that I
add user group-1-* {user1}
add user group-2-* {user2}
Unfortunately I am unable to describe groups of devices in such a
add user 192.168.1.* {user1}
add password 192.168.1.* {pass1}
add user 192.168.2.5 {user1}
add password 192.168.2.5 {pass1}
add user *-core-* {user1}
add password *-core-* {pass1}
add user 10.1.2.3 {user2}
add user 10.1.5.* {user2}
etc..
Is it possible to use regular expression to describe hostname? I'd
add user {192.168.1.*|192.168.2.5|*-core-*} {user1}
add password {192.168.1.*|192.168.2.5|*-core-*} {pass1}
add user {10.1.2.3|10.1.5.*} {user2}
...
Best regards,
Pawel Rzepa
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo/rancid-discuss
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo/rancid-discuss
/Peo
----------------------------------------------------------
Per-Olof Olsson Email: ***@chalmers.se
Chalmers tekniska högskola IT-service
Arvid Hedvalls backe 6 412 96 Göteborg
Tel: 031/772 6738 Fax: 031/772 8680
----------------------------------------------------------