我正在编写bash脚本,将数据从AWS S3桶复制到Linux。
#!/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://"/ mydumper --exclude "*" --include "collegeboard.*" --recursive
expect << 'EOS'
spawn sftp @:/Bobby
expect "Password:"
expect "sftp>"
send "\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 @:/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""发布于 2021-09-22 11:19:54
看看像这样在expect中定义CURRENT_DATE是否有效。
expect << 'EOS'
spawn sftp @:/Bobby
expect "Password:"
expect "sftp>"
send "\n"
expect "sftp>"
send "mkdir $::env(CURRENT_DATE)\n"
send "cd $::env(CURRENT_DATE)\n"https://unix.stackexchange.com/questions/670082
复制相似问题