![将数据从 AWS S3 存储桶复制到 Linux SFTP](https://linux22.com/image/195989/%E5%B0%86%E6%95%B0%E6%8D%AE%E4%BB%8E%20AWS%20S3%20%E5%AD%98%E5%82%A8%E6%A1%B6%E5%A4%8D%E5%88%B6%E5%88%B0%20Linux%20SFTP.png)
我正在编写 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"