AWS S3 버킷의 데이터를 Linux SFTP로 복사하기 위해 bash 스크립트를 작성 중입니다.
#!/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"