Issue
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
Solution
#!/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.
Answered By - user19001067 Answer Checked By - David Marino (WPSolving Volunteer)