config.xml配置文件如下:------------------------------------------------
name=tester ;#用户名
password=vmkid ;#密码
common.exp脚本如下:---------------------------------------------------
#!/usr/bin/expect
proc getConfig {configFile Key {Comment "#"} {Equal "="}} { ;#过程中如果参数有缺省值,使用花括号引起,并赋值
set Value "" ;# 记录过程返回的值
# 打开配置文件
set err [catch {set fileid [open $configFile r]} errMsg]
if {$err == 1} {
puts "errMsg : $errMsg"
return $Value
}
# 成功打开文件后, 一行一行的加以分析
set rowid 0 ;#记录当前行数,程序调试时打印调试信息使用的
while {[eof $fileid] != 1} { ;# 读取文件内容
incr rowid ;# 记录行数, 从一开始
gets $fileid line ;# 读出一行
# 先去掉注释, 再去掉两端的空格
set commentpos [string first $Comment $line] ;# 得到注释符号的位置
if { $commentpos != 0 } {
# 行以注释符号开头,忽略掉该行
} else {
if { $commentpos != -1 } { ;# 行中有注释符号,去掉注释
set line [string range $line 0 [expr $commentpos-1]]
}
set line [string trim $line] ;# 去掉两端的空格
# puts "$rowid : line : $line"
# 如果是空就继续循环
if { $line == "" } {
continue
} else {
set equalpos [string first $Equal $line] ;# 得到等号的位置
if { $equalpos != -1} {
# 如果就是找寻的key,结束循环
if { [string range $line 0 [expr $equalpos - 1]] == $Key } {
set Value [string range $line [expr $equalpos + 1] [string length $line]]
break
}
}
}
}
}
# 关闭文件
close $fileid
#返回值
return $Value
}
set val [getConfig "config.xml" "password"]
puts "---------val: $val"
exit
expect eof
分享到:
相关推荐
Tcl/Expect学习心得:等待操作是很有用的及COM通讯脚本
NULL 博文链接:https://j2ee2009.iteye.com/blog/824829
tcl脚本语言安装包,要安装expect脚本,必须先安装tcl。 一)Tcl 安装 ... 下载地址: http://www.tcl.tk/software/tcltk/downloadnow84.tml 1.下载源码包 ...ln -s /usr/tcl/bin/expect /usr/expect/bin/expect
这个是讲解Tcl/tk 中Expect用法的书,讲的同时结合实例,很易懂。绝对是入门的好材料。
使用tcl / expect编写的简单sms网关,使用mysql作为文本消息的数据源。
expect据说是交互性很强的脚本语言,但是expect依赖于tcl,但linux系统里一般不自带安装tcl,需要手动安装
tcl和expect安装包,适合离线部署。请对于自动输入密码又需求的小伙伴们下载哈~
expect实现 shell 交互式网络命令,插件安装: tar xzvf expect5.45.tar.gz cd expect5.45 ./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-...ln -s /usr/tcl/bin/expect /usr/expect/bin/expect
Tcl,Tcl语言,expect,可用于交互式自动化脚本,方便自动化管理服务器。
expect5.45.4.tar tcl8.4.11-src.tar
linux交互式编程expect的基础包
简单介绍tcl语言以和expect语法以及使用方法
Tcl 进程和文件 I/O 29 将 eval 用于动态脚本 32 Tk 命令 34 小部件 34 Hello, World! Tk 样式 34 Tk 演示 36 Tk 小部件的分类取样器 36 Tk 命令,第一部分 38 Tk 命令,第二部分 39 真的(小)Tk 应用程序 39 样本 ...
expect.deb离线包,包含 expect_5.45-2_amd64.deb tcl8.5_8.5.11-1ubuntu1_amd64.deb两个 使用命令 dpkg --install expect_5.45-2_amd64.deb dpkg --install tcl8.5_8.5.11-1ubuntu1_amd64.deb 可以直接进行安装,不...
Introduction to Expect The Expect package was installed in the LFS temporary tools directory for testing other packages....Download (HTTP): https://downloads.sourceforge.net/expect/expect5.45.4.tar.gz
centos7、centos8安装expect及tcl所需的安装包...下载完拷贝到linux系统文件目录下,unzip expect_tcl.zip,然后执行sh install_expect.sh 即可完成tcl和expect的安装 安装完毕后,可以输入expect测试能否执行expect命令
expect and tcl 安装包和安装手册 Expect是在Tcl基础上创建起来的,它还提供了一些Tcl所没有的命令,它可以用来做一些linux下无法做到交互的一些命令操作,在远程管 理方面发挥很大的作用。 spawn命令激活一个Unix...
在centos-7上,本人下载好的安装包。 yum install --downloadonly --downloaddir=./ expect expect-dev tcl 可以直接安装,摆脱网络依赖。