【问题标题】:EOF in expect script spawning sftp期望脚本产生 sftp 中的 EOF
【发布时间】:2022-01-21 08:37:30
【问题描述】:

我有一个将文件从 linux 服务器传输到 windows 服务器的脚本。我想记录与传输相关的数据,但 EOF 在 HEREDOC 构造中给了我错误。谁能告诉我前进的方向。

我的脚本是:

#!/usr/bin/expect
spawn sftp XXXX@XXXXXX <<EOF>> log.file
expect "password:"
send "ABC\n"
expect "sftp>"
send "cd /FIRST\r"
expect "sftp>"
send "lcd /home\r"
expect "sftp>"
send "mput /home/*First*\r"
send "bye\r"
interact

【问题讨论】:

    标签: linux sftp expect eof heredoc


    【解决方案1】:

    或者

    #!/usr/bin/expect
    log_file -a log.file
    spawn sftp XXXX@XXXXXX
    # ... the rest is all the same.
    

    如果您实际上并未(作为人)与 sftp 进程进行交互,则可以将其用作最后一行

    expect eof
    

    【讨论】:

      【解决方案2】:

      改为使用 shell 脚本并调用 expect 传递给它“-”以使其从其标准输入读取,这将是 HEREDOC(即

      #!/bin/sh
      
      /usr/bin/expect - <<EOF >> /tmp/log
      spawn sftp XXXX@XXXXXX
      expect "password:"
      send "ABC\n"
      expect "sftp>"
      send "cd /FIRST\r"
      expect "sftp>"
      send "lcd /home\r"
      expect "sftp>"
      send "mput /home/*First*\r"
      send "bye\r"
      EOF
      

      【讨论】:

        猜你喜欢
        • 2020-07-01
        • 2014-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多