将数据从 AWS S3 存储桶复制到 Linux SFTP

将数据从 AWS S3 存储桶复制到 Linux SFTP

我正在编写 bash 脚本以将数据从 AWS S3 存储桶复制到 Linux SFTP。

#!/bin/bash
#!/usr/bin/expect
set CURRENT_DATE [lindex $argv 0]

CURRENT_DATE=`date +"%Y%m%d"`
cd /home/ubuntu/test/mydumper

aws s3 cp s3://<directory_path>"/ mydumper --exclude "*" --include "collegeboard.*" --recursive

expect << 'EOS'
spawn sftp <user_name>@<Ip_address>:/Bobby
expect "Password:"
expect "sftp>"
send "<password>\n"
expect "sftp>"
send "mkdir $CURRENT_DATE\n"
send "cd $CURRENT_DATE\n"
send "mput collegeboard.*\n"
expect "sftp>"
send "pwd\n"
expect "sftp>"
send "bye\n"
EOS

我面临以下错误:

spawn sftp <user_name>@<Ip_address>:/Bobby
Password Authentication
Password:
Connected to fts.collegeboard.com.
Changing to: /Bobby
sftp> pwd
Remote working directory: /Bobby
sftp> can't read "CURRENT_DATE": no such variable
    while executing
"send "cd $CURRENT_DATE""

答案1

看看在expect中像这样定义CURRENT_DATE是否有效。

expect << 'EOS'
spawn sftp <user_name>@<Ip_address>:/Bobby
expect "Password:"
expect "sftp>"
send "<password>\n"
expect "sftp>"
send "mkdir $::env(CURRENT_DATE)\n"
send "cd $::env(CURRENT_DATE)\n"

相关内容