免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4462 | 回复: 16

[系统管理] expect 交互 捕获中文 [复制链接]

论坛徽章:
0
发表于 2017-02-21 15:24 |显示全部楼层
expect {
"*keypass*" {send "$passwd\r"}
"*再次输入密码*" {send "$passwd\r"}
}

expect 如何捕获中文字符并赋值


论坛徽章:
0
发表于 2017-02-21 18:03 |显示全部楼层
三码合一 就可以捕获中文了~~!

论坛徽章:
0
发表于 2017-02-22 09:37 |显示全部楼层
回复 2# nuclearxin

怎么合?? 不太懂

论坛徽章:
0
发表于 2017-02-22 12:25 |显示全部楼层
回复 3# 林间笑客

中文 要保证1.你的环境 编码支持中文
2.term终端 支持中文编码
3. 你中文来源 确实是对应的中文编码



论坛徽章:
0
发表于 2017-02-22 12:59 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
发表于 2017-02-22 14:35 |显示全部楼层
回复 4# nuclearxin

这个问题解决了,现在出现了这个: 组织名?
[Unknown]
姓名?
[Unknown]
组织结构代码?
[Unknown]


输入项全是
[Unknown]: 这如何去捕捉?? 如何去判别??
怎么将值 expect{  " [Unknown]"  {send} }  ???

论坛徽章:
0
发表于 2017-02-22 14:53 |显示全部楼层
林间笑客 发表于 2017-02-22 14:35
回复 4# nuclearxin

这个问题解决了,现在出现了这个: 组织名?

描述的不够详细。数据是怎么出来的 你是怎么输入的?
一次都出来还是你 交互按下回车?

输出在不同行就在一个 expect 里面 嵌套吧



论坛徽章:
0
发表于 2017-02-22 15:45 |显示全部楼层
本帖最后由 林间笑客 于 2017-02-22 15:55 编辑

回复 7# nuclearxin


这是交互手动输入的,
Enter keystore password:  
Re-enter new password:
What is your first and last name?
  [Unknown]:  SSS
What is the name of your organizational unit?
  [Unknown]:  SSS
What is the name of your organization?
  [Unknown]:  SSS
What is the name of your City or Locality?
  [Unknown]:  chengdu
What is the name of your State or Province?
  [Unknown]:  sichuan
What is the two-letter country code for this unit?
  [Unknown]:  86
Is CN=SSS, OU=SSS, O=SSS, L=chengdu, ST=sichuan, C=86 correct?
  [no]:  y


我的代码

/usr/bin/expect <<-EOF
spawn keytool -genkey -alias server -keyalg RSA -keysize 2048 -keystore server.keystore
expect {
"*keystore*" {send "SSS\r";exp_continue}
"?*new*" {send "SSS\r"}
"?*n]:" {send "SSS\r"}
"?*organizational*" {send "SSS\r"}
"?*organization?*"  {send "SSS\r"}
"?*Locality?*"  {send "chengdu\r"}
"?*Province*" {send "sichuan\r"}
"?*two-letter*"  {send "86\r"}
"?*no*" {send "y\r"}
"?*password):" {send "$passwd\r"}
}
expect "*#"
spawn keytool-import -trustcacerts -alias root -file root.crt -keystore server.keystore
expect {
"keystore:*" {send  "$passwd\r"}
"*]*" {send "y\r"}
}
expect "*#"
interact
expect eof
EOF

论坛徽章:
0
发表于 2017-02-22 16:27 |显示全部楼层
你高估tcl的 expect 的流程控制了
他没有流程控制。。。。你要自己实现:
我不太记得详细语法了不过
应该是


while {

  expect {



  }

}

expect 只会执行一次

应该也可以  expect {    send foo ; print x ;  expect  { } }
嵌套

总之都要自己实现。
  

论坛徽章:
0
发表于 2017-02-22 16:43 |显示全部楼层
回复 9# nuclearxin

是这样的么??
如果下面的
What is your first and last name?
  [Unknown]: 回车\r
What is the name of your organizational unit?
  [Unknown]:   回车\r
What is the name of your organization?
  [Unknown]:   回车\r
What is the name of your City or Locality?
  [Unknown]:   回车\r
What is the name of your State or Province?
  [Unknown]:   回车\r
What is the two-letter country code for this unit?
  [Unknown]:   回车\r
Is CN=pinnettech, OU=pinnettech, O=pinnettech, L=chengdu, ST=sichuan, C=86 correct?
  [no]:  y


就是什么都不输入直接进入下一步可以么??又要怎么实现呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP