Shell 将所有*.gz文件推送到aws s3存储桶时出错-“;bash:-c:0行:意外标记“then'&引用;
我试图将所有*.gz文件推送到aws s3存储桶,但我收到了以下错误bash:-c:line 0:意外标记附近的语法错误'then' ssh root@“find/tmp/-name”localhost_*.gz“-mtime-1-exec s3cmd 将“{}”放在s3://script testing/test1/\;如果[$?==“0”];则回显 \“成功将备份推送到s3 bucket\”| mail-s \“已成功将备份推送到S3\”电子邮件id;“else echo\”失败 将日志推送到S3存储桶\“邮件-s\”无法将日志推送到S3\” 电子邮件id;fi“ 将-exec命令放入一个单独的shell脚本中会更简单(更清晰),这样就不必转义引号等,也不必问以下问题:Shell 将所有*.gz文件推送到aws s3存储桶时出错-“;bash:-c:0行:意外标记“then'&引用;,shell,amazon-s3,Shell,Amazon S3,我试图将所有*.gz文件推送到aws s3存储桶,但我收到了以下错误bash:-c:line 0:意外标记附近的语法错误'then' ssh root@“find/tmp/-name”localhost_*.gz“-mtime-1-exec s3cmd 将“{}”放在s3://script testing/test1/\;如果[$?==“0”];则回显 \“成功将备份推送到s3 bucket\”| mail-s \“已成功将备份推送到S3\”电子邮件id;“else echo\”失败 将日志推送
remote$ cat myscript.sh
s3cmd put "$1" s3://script-testing/test1/
if [ $? == "0" ] ; then
...
local$ ssh ... -exec myscript.sh '{}' \;
尽管如此:
remote$ cat myscript.sh
s3cmd put "$1" s3://script-testing/test1/
if [ $? == "0" ] ; then
...
local$ ssh ... -exec myscript.sh '{}' \;
尽管如此:
remote$ cat myscript.sh
s3cmd put "$1" s3://script-testing/test1/
if [ $? == "0" ] ; then
...
local$ ssh ... -exec myscript.sh '{}' \;
尽管如此:
remote$ cat myscript.sh
s3cmd put "$1" s3://script-testing/test1/
if [ $? == "0" ] ; then
...
local$ ssh ... -exec myscript.sh '{}' \;
尽管如此:
ssh root@host $'find /tmp/ -name \'localhost_*.gz\' -mtime -1 -exec s3cmd put \'{}\' s3://script-testing/test1/ \\;\n\nif [ $? == 0 ]\nthen \n echo "Successfully pushed the backup to s3 bucket" | mail -s "Successfully pushed backup to S3 "\nelse \n echo "Failed pushing logs to S3 Bucket" | mail -s "Failed Pushing logs to s3"\nfi'
# I'm assuming for simplicity that there is no whitespace in any of the
# files that find will match.
find /tmp/ -name "localhost_*.gz" -mtime -1 | while read fame; do
if s3cmd put "$fname" s3://script-testing/test1/; then
msg="Successfully pushed the backup $fname to s3 bucket"
else
msg="Failed pushing the backup $fname to s3 bucket"
fi
echo "$msg"
done | mail -s "Results of pushing backups to s3 bucket" email-id
scp script.sh host:
ssh root@host bash script.sh