如何在bash脚本中使用expect

时间:2017-07-17 13:04:31

标签: bash expect

有人可以告诉我为什么这不起作用吗?

.test{
 background: red;
 width: 100%;
 height: 500px;
}

/*for screen width of 786px*/
@media screen and (max-width: 786px){
   .test{
     background: blue;
   }
}

/*for screen width of 300px*/
@media screen and (max-width: 300px){
   .test{
     background: green;
   }
}

它没有给出任何错误,但文件没有传输到远程服务器。我已经尝试了很多方法仍然无法找到任何解决方案。

1 个答案:

答案 0 :(得分:4)

您定义的bash脚本是在expect的标准输入上传递expect命令。但是,expect命令需要使用-c选项将其参数作为文件或参数。

您有几个选项,但要在脚本上添加较少的修改,您只需使用进程替换为expect命令创建here-document(临时)。

#!/bin/bash 

  echo "[DEBUG] INIT BASH"

  cd /home
  touch somefile

  /usr/bin/expect <(cat << EOF
spawn scp -r -P remoteServerPort somefile remoteServerIP:/home
expect "Password:"
send "MyPassWord\r"
interact
EOF
)

  echo "[DEBUG] END BASH"
相关问题