expect命令怎么用?

来源:互联网 发布:linux的cp命令~ 编辑:程序博客网 时间:2024/05/15 09:49

我有这样一段交互:

root@ffdf50d37cdd:/# dotnet /miner/Miner.dll /rpcant>open wallet /miner_data/wallets/1.db3password:*[07:37:21] StartMine

上面交互过程大概是:
1. 使用dotnet命令启动Miner.dll
2. 使用open wallet命令打开一个文件/miner_data/wallets/1.db3
3. 输入密码
4. 程序正常运行后马上输出StartMine等日志;如果密码错误,出现提示failed to open file "/miner_data/wallets/1.db3"
5. 步骤2、3也可能出现异常信息error,此时从步骤2重新执行即可。

由于我要把这段程序放在docker生产环境中运行,所以要把这段人工交互过程改成程序自动交互的。初步研究后发现expect命令有这个功能,于是写了下面的一段代码test.sh

#!/usr/bin/expectexpect -c "  spawn dotnet /miner/Miner.dll /rpc  expect "ant\>"  send "open wallet /miner_data/wallets/1.db3\r"  expect "password:"  send "1\r""

尝试运行这段代码,却发现结果不对:

root@ffdf50d37cdd:/# sh a.shspawn dotnet /miner/Miner.dll /rpcant>couldn't read file "wallet": no such file or directoryroot@ffdf50d37cdd:/# 

请教各位看官,这段shell脚本哪里不对呢?要完成这个任务应该怎么写shell脚本呢?欢迎各位不吝赐教留言或者给我邮件cn.binbin@qq.com

0 0
原创粉丝点击