Home > database >  EOF in expect script spawning sftp
EOF in expect script spawning sftp

Time:12-20

I have a script that is transferring files from a linux server to a windows server. I want to log the data related to the transfers but EOF is giving me error in the HEREDOC construct. 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

CodePudding user response:

Use a shell script instead and call expect passing to it "-" to make it read from its standard input which will be the HEREDOC (i.e. <<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

CodePudding user response:

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

expect eof
  • Related