发送:产卵ID exp7打不开 [英] send: spawn id exp7 not open

查看:374
本文介绍了发送:产卵ID exp7打不开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行autoexpect文件我得到一个错误发送:产卵ID exp7不公开
这是我的文件 sh.exp

When I try to execute autoexpect file I get an error send: spawn id exp7 not open Here is my file sh.exp:

#!/usr/bin/expect

# mysql credentials and connection data
db_host='localhost'
db_name='webui_dev'
db_user='root'
db_pass=''
new_db_name='db_2011'

expect <<EOF
  log_user 0
  spawn mysql -h $db_host -u $db_user -p $db_pass 'create database $new_db_name'
  expect "password:"
  send "$db_pass\r"
  log_user 1
  expect eof
EOF

找不到在哪里是错误的。

Can't find where is an error.

推荐答案

尝试正确引用您的变量:

Try quoting your variables properly:

  spawn mysql -h "$db_host" -u "$db_user" -p "$db_pass" "create database $new_db_name"

在双引号中没有报价变量都受到字的拆分和路径扩展。下单引号变量不扩大。了解更多关于shell引用 rel=\"nofollow\">。

Variables not quoted in double quotes are subject to word splitting and pathname expansion. And variables under single quotes don't expand. Read more about shell quoting here.

更新:看来你实际上是通过在这里的文档扩展它,但它仍然适用,因为你的论点仍然需要引期待。这就是它会出现输入期望:

Update: It seems that you're actually expanding it through a here document, but it would still apply since your arguments still need to be quoted in expect. This is what it would appear as input to expect:

  log_user 0
  spawn mysql -h "localhost" -u "root" -p "" "create database db_2011"
  expect "password:"
  send "\r"
  log_user 1
  expect eof

这是如果你还没有引用它尚未怎么会出现:

This is how it would appear if you haven't quoted it yet:

  ...
  spawn mysql -h localhost -u root -p  'create database db_2011'
  ...

更新:

问题的原因其实是因为MySQL很快结束,而不显示,由于额外的参数密码的提示。解决的办法是手动发送该命令。它也preferable只运行整个脚本作为expect脚本,而不是嵌入的一个较小的混乱

The cause of the problem actually is because mysql ends quickly without showing a prompt for password due to the extra argument. The solution is to send the command manually. It's also preferable to just run the whole script as an expect script, not an embedded one for lesser confusion

#!/usr/bin/expect

# mysql credentials and connection data
set db_host "localhost"
set db_name "webui_dev"
set db_user "root"
set db_pass ""
set new_db_name "db_2011"

log_user 0
spawn mysql -h "$db_host" -u "$db_user" -p
expect "password:"
send "$db_pass\r"
expect "mysql>"
send "create database $new_db_name; exit; \r"
log_user 1
expect eof

将脚本保存为一个文件,期望和运行它预计-f expect_file

这篇关于发送:产卵ID exp7打不开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆