简体   繁体   English

期望脚本产生 sftp 中的 EOF

[英]EOF in expect script spawning sftp

I have a script that is transferring files from a linux server to a windows server.我有一个脚本将文件从 linux 服务器传输到 windows 服务器。 I want to log the data related to the transfers but EOF is giving me error in the HEREDOC construct.我想记录与传输相关的数据,但 EOF 在 HEREDOC 构造中给了我错误。 Can anyone show me the way forward for this.谁能告诉我前进的方向。

My script is:我的脚本是:

#!/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

Use a shell script instead and call expect passing to it "-" to make it read from its standard input which will be the HEREDOC (ie <<EOF... EOF):改用 shell 脚本并调用expect传递给它“-”以使其从其标准输入读取,该输入将是 HEREDOC(即 <<EOF...EOF):

#!/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

Or或者

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

If you're not actually interacting (as a human) with the sftp process, you could use this as the last line如果您实际上并未(作为人类)与 sftp 进程进行交互,则可以将其用作最后一行

expect eof

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM