⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commonlib.tcl

📁 tcl例子脚本
💻 TCL
字号:
#************************************************ 
# get a line from file, skip blank lines and
# comment lines, return the reading line in
# parameter 'line'.
#
# @PARAMS
# fd     - file fd
# line   - var used to return the line
# 
# @RETURN
# return 1 if read successfully, otherwise 0
#************************************************ 
proc getLine {fd line} {
    upvar $line ln

    # read a line from fd
    while {[set lineLen [gets $fd ln]] >= 0} {
        # blank line
        if { $lineLen == 0 } continue
 
        # trim whitespace
        set ln [string trim $ln]
        if { [string length $ln] == 0 } continue

        # skip comment
        if { [string index $ln 0] == "#" } continue

        # success
        return 1
    }

    return 0
}


#************************************************ 
# debug output routine
#
# @PARAMS
# arg - variable length arguments
#************************************************ 
proc dbgLog arg {
    global g_dbgFlag

    if {$g_dbgFlag} {
        puts $arg
    }
}

#************************************************ 
# error output routine
#
# @PARAMS
# arg - variable length arguments
#************************************************ 
proc errLog arg {
    global g_bLogFd
    global g_dbgFlag

    if {$g_dbgFlag} {
        puts $arg
    }

    if { $g_bLogFd != 0 } {
        puts $g_bLogFd $arg
    }
}

#************************************************ 
# telnet login routine
#
# @PARAMS
# ipaddr - remote device ip address
# user   - user name to login in
# passwd - login password
# 
# @RETURN
# spawn_id if login success, otherwise 0
#************************************************ 
proc login {ipaddr user passwd} {
    global g_prompt g_usrPrompt g_pwdPrompt prompt

    spawn telnet $ipaddr
    expect {
        "$g_usrPrompt" {
            exp_send "$user\r"
            exp_continue
        }
        "$g_pwdPrompt" {
            exp_send "$passwd\r"
            exp_continue
        }
        "$g_prompt" {
            #dbgLog "Login Successful\n"
            exp_send "co\r"
            exp_continue
        }
        "$prompt" {
            dbgLog "登陆成功,进入配置模式\n"
            return $spawn_id
        }
        timeout {
            send_user "timeout\n"
            return 0
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -