Thompson
Thompson

Reputation: 2000

AWS commands not getting executed on CRONTAB

Before I proceed, please let me tell that I tried all methods mentioned at stackoverflow and other forums but nothing worked on my CentOS 6.8 server.

Here is what I have written in crontab

00 5 * * * /usr/bin/aws /var/www/html/james/crons/s3_downloader.sh

And s3_downloader.sh file full content is:

#!/bin/bash
aws s3 sync "s3://my_bucket/my_folder/" "/var/www/html/james/downloads/my_folder/";

But nothing is working when cron tab runs it. However everything works fine when I run it via command line screen on server.

My server has installed the AWS at path (using ROOT user): /usr/bin/aws (using which aws)

Here is the methods I have tried (but nothing worked for me):

-->Changed the path for aws in file contents:

#!/usr/bin/aws
aws s3 sync "s3://my_bucket/my_folder/" "/var/www/html/james/downloads/my_folder/";

--> Did export settings on ROOT console

export AWS_CONFIG_FILE="/root/.aws/config"
export AWS_ACCESS_KEY_ID=XXXX
export AWS_SECRET_ACCESS_KEY=YYYY

Edit: When I logged the response from crontab to a log

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: argument command: Invalid choice, valid choices are:

Here is full response: http://pastebin.com/XAKQUVzT

Edit 2

After more debugging, I can see the error coming out (in cron log) is:

env: /var/www/html/james/crons/s3_downloader.sh: Permission denied

Upvotes: 0

Views: 930

Answers (2)

user19001067
user19001067

Reputation: 16

#!/bin/sh

cd path of the folder with scripts

/usr/local/bin/aws ec2 stop-instances --instance-ids idoftheinstance

Include the path of aws /usr/local/bin/aws and good.

Upvotes: 0

jarmod
jarmod

Reputation: 78633

Your crontab entry is wrong. You have passed the name of your shell script (/var/www/html/james/crons/s3_downloader.sh) as a parameter to /usr/bin/aws.

You should either call aws s3 sync directly from within the crontab entry, or call your shell script (and make the shell script call aws s3 sync), but you're trying to do both.

So, change the crontab entry to execute the shell script (and make sure that the shell script is actually executable).

00 5 * * * /var/www/html/james/crons/s3_downloader.sh

Upvotes: 2

Related Questions