手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

expect: spawn id exp3 not open

首页 > Linux >

在尝试使用 envoy  尝试自动部署的时候,遇到了问题,即:如果我要自己创建一个新的域名,那只能上线去执行 lnmp vhost add 的命令。

为什么要使用 lnmp 呢?其实他对我的作用只有一个,多版本的 PHP。因为现在在线上,各种不同版本的 PHP 都在跑,有 PHP5.6 / PHP7.1 / PHP8.1估计后面还会有更多的版本。
 
于是,我就想着用 expect 来处理

sudo /usr/bin/expect<<EOF
spawn lnmp vhost add
expect {
    "Please enter domain" {send "{{$host}}\n";exp_continue}
    "Enter more domain name"  {send "\n";exp_continue}
    "Please enter the directory" {send "\n";exp_continue}
    "Allow Rewrite rule" {send "y\n";exp_continue}
    "Default rewrite" {send "laravel\n";exp_continue}
    "Enable PHP Pathinfo" {send "\n";exp_continue}
    "Allow access log" {send "\n";exp_continue}
    "Enable IPv6" {send "\n";exp_continue}
    "Enter your choice " {send "\n";exp_continue}
    "Add SSL Certificate" {send "\n";exp_continue}
    "Press any key to start" {send "\r"; exp_continue}
}
expect eof
EOF
但执行后一直报错:
[mpass]: expect: spawn id exp3 not open
[mpass]: while executing
[mpass]: "expect eof"
 
仔细查了半天,原来最后一句还用了 exp_continue。。expect 认为还没有执行完。所以。就行报错了。
将最后一个 exp_contiue 删除。再次执行,就正常了
XML/HTML代码
  1. @task('lnmp' ,['on'=>'dev'])  
  2.   
  3. @if($force)  
  4.     sudo rm -rf /usr/local/nginx/conf/vhost/{{$host}}.conf  
  5.     sudo rm -rf /home/wwwroot/{{$host}}  
  6. @endif  
  7. sudo /usr/bin/expect<<EOF  
  8. spawn lnmp vhost add  
  9. expect {  
  10.     "Please enter domain" {send "{{$host}}\n";exp_continue}  
  11.     "Enter more domain name"  {send "\n";exp_continue}  
  12.     "Please enter the directory" {send "\n";exp_continue}  
  13.     "Allow Rewrite rule" {send "y\n";exp_continue}  
  14.     "Default rewrite" {send "laravel\n";exp_continue}  
  15.     "Enable PHP Pathinfo" {send "\n";exp_continue}  
  16.     "Allow access log" {send "\n";exp_continue}  
  17.     "Enable IPv6" {send "\n";exp_continue}  
  18.     "Enter your choice " {send "\n";exp_continue}  
  19.     "Add SSL Certificate" {send "\n";exp_continue}  
  20.     "Press any key to start" {send "\r";}  
  21. }  
  22. expect eof  
  23. EOF  
  24. ls -lah /home/wwwroot/  
  25. @endtask  
这样就 OK 了



本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"易栈网-膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

Tags: envoy, expect

« 上一篇 | 下一篇 »

发表评论

评论内容 (必填):