简体   繁体   English

运行cron会产生与运行其命令不同的结果

[英]Running cron produces different result than running its command

I have the following script that saves a db backup to s3: 我有以下脚本将数据库备份保存到s3:

# next, backup the mysql `premiered` database to the backups folder
echo successfully backed up mysql databasee
mysqldump --single-transaction -u root test | gzip  > $BACKUPFOLDER/$CONNECT

# finally, save the backups to s3 via s3fs
s3fs test-backups ./s3fs
cp $BACKUPFOLDER/$CONNECT ./s3fs/$CONNECT
echo succeessfully saved sql file to s3

When I run this as a shell command, $ ./backup.sh , it correctly saves the file to S3. 当我将它作为shell命令$ ./backup.sh ,它正确地将文件保存到S3。 However, when I run this command via cron, it literally saves the file to the local ./s3fs folder and does not save it to S3. 但是,当我通过cron运行此命令时,它实际上将文件保存到本地./s3fs文件夹,并且不将其保存到S3。 Why does this occur and what do I need to do to fix this? 为什么会发生这种情况,我需要做些什么才能解决这个问题?

The cron job executes under user cron that does not, by default, have access to your S3 credentials. cron作业在用户cron下执行,默认情况下,它不能访问您的S3凭据。 I suppose you store them in your S3_* environment variables, but the cron job executes with an almost empty environment. 我想你将它们存储在S3_*环境变量中,但是cron作业在几乎为空的环境中执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM