我正在使用脚本dump-to-s3.sh
将数据库转储放入S3存储桶中。
当手动触发时,它可以正常工作,但是当我通过此cron(作为root crontab)触发它时,它会失败,并显示以下错误消息:
的crontab
31 12 * * * /home/dokku/.mongodb/dump-to-s3.sh
来自CURL的错误
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided.
Check your key and signing method.</Message>...
dump-to-s3.sh
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
#cd to dump-folder
cd /dump/folder
file="mydump.tar.gz"
bucket="mybucket"
resource="/${bucket}/dumps/${file}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key="xxxxxxxxxxxxxxxx"
s3Secret="xxxxxxxxxxxxxxxx"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/dumps/${file}
答案 0 :(得分:3)
我认为您可能需要手动运行bash
,例如
/bin/bash /home/dokku/.mongodb/dump-to-s3.sh
-en
的{{1}}选项不适用于常规shell;它可能只是一个bash扩展。
在echo
:
sh
在$ sh
sh-3.2$ echo -en foo
-en foo
sh-3.2$
:
bash