From: Aric Bills on
Richard, I don't mean any disrespect, but for the sake of the original
poster I want to point out some errors in your code, lest he spend
hours poring over it and becoming very confused.

On 1 mar, 14:55, Richard Owlett <rowl...(a)pcnetinc.com> wrote:
>
> proc EditUserName {username file_of_users} {
> # file_of_users is name of file containing known
> # IP addresses
> #
>     if { [ string length $username ] <> 34} {

"<>" is invalid. Use "!=" instead.


>         return $username            ;# return original user id
>         }
>     else {
>         set a [split $username {}]  ;# convert string to list
>         set b [lrange $a 18 25]     ;# b now has user IP

It doesn't make any sense to convert the string to a list. Use
[string range] to extract part of a string.


>         set f [open $file_of_users]
>         set u [read $f]             ;# u has the all known users
>         set u [split $u {}]

You haven't thought through the consequences of that last line. It
will create a list where every item is a single character, including
any whitespace characters that may be present in the file.


>         close $f
>         set flag [lsearch -exact $u $b] ;# -1 if no match

This will always fail, because every item in $u is a single character,
while $b is a list.


>         if {[$flag > -1]} {
>            return [lrange $a 0 25]  ;# return truncated user id
>            }
>         else {
>            return $username         ;# return original user id
>            }
>         }
>    }
From: Richard Owlett on
Aric Bills wrote:
> Richard, I don't mean any disrespect, but for the sake of the original
> poster I want to point out some errors in your code, lest he spend
> hours poring over it and becoming very confused.

Not to worry, when I noted that I was also a "newbie" it was sort
of "caveat lector".
So now two newbies have chance to learn.
Thank you.



>
> On 1 mar, 14:55, Richard Owlett <rowl...(a)pcnetinc.com> wrote:
>> proc EditUserName {username file_of_users} {
>> # file_of_users is name of file containing known
>> # IP addresses
>> #
>> if { [ string length $username ] <> 34} {
>
> "<>" is invalid. Use "!=" instead.
>
>
>> return $username ;# return original user id
>> }
>> else {
>> set a [split $username {}] ;# convert string to list
>> set b [lrange $a 18 25] ;# b now has user IP
>
> It doesn't make any sense to convert the string to a list. Use
> [string range] to extract part of a string.
>
>
>> set f [open $file_of_users]
>> set u [read $f] ;# u has the all known users
>> set u [split $u {}]
>
> You haven't thought through the consequences of that last line. It
> will create a list where every item is a single character, including
> any whitespace characters that may be present in the file.
>
>
>> close $f
>> set flag [lsearch -exact $u $b] ;# -1 if no match
>
> This will always fail, because every item in $u is a single character,
> while $b is a list.
>
>
>> if {[$flag > -1]} {
>> return [lrange $a 0 25] ;# return truncated user id
>> }
>> else {
>> return $username ;# return original user id
>> }
>> }
>> }
From: Don Pich on
Hello Aric,

Thanks for your input. I had one question...

I believe that one of the requirements is that this all be placed under
one proc. Is there any problem with doing it that way?

Thanks,
Don
From: Aric Bills on
On 2 mar, 08:07, Don Pich <dp...(a)polartel.com> wrote:
> Hello Aric,
>
> Thanks for your input.  I had one question...
>
> I believe that one of the requirements is that this all be placed under
> one proc.  Is there any problem with doing it that way?
>
> Thanks,
> Don

It's less efficient, but if you have some good reason to re-read the
contents of the file every time, you can certainly do all that in the
same proc. In that case you wouldn't need a global variable
containing the contents of the file.
From: Don Pich on
Hello Aric,

I have had a chance to add this to my Cisco radius server. What I have
done is added two seperate tcl files instead of just one. It seems to be
having a problem with the reading the list.

--> reload

Reloading Server 'Radius'...
310 Command failed
Server 'Radius' failed to start
The server wrote the following errors to the log file:
Configuration Error evaluating Tcl file /opt/CSCOar/scripts/radius/
tcl/ReadUserList.tcl


-->


[root(a)rad-a tcl]# cat ReadUserList.tcl
proc ReadUserList {filename} {
variable BAS_list
set filehandle [open $filename r]
set contents [read $filehandle]
close $filehandle
set BAS_list [regexp -all -inline {\S+} $contents]
}

read_BAS_list /opt/CSCOar/scripts/radius/tcl/BASIP.list
[root(a)rad-a tcl]#

I'm wondering if there is another method to incorporate the data stored
in BASIP.list instead of this method. I don't know exactly what Cisco's
AR is having fits about.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Compiling
Next: "open" issue in a new defined namespace