ablog

不器用で落着きのない技術者のメモ

cron から AWS CLI を実行してみる

cron から AWS CLI を実行してみたメモ。

  • cron の設定
$ crontab -l
*  *  *  *  * /bin/bash /home/ec2-user/jobs/job01.sh
  • job01.sh
#!/bin/bash
export LANG=C
export TZ="Asia/Tokyo"
BASE_DIR=$(cd $(dirname $0);pwd)
BASE_NAME=$(basename $0)
STEM="${BASE_NAME%.*}"
AWS_CONFIG_FILE=~/.aws/config

cd ${BASE_DIR}
aws s3 ls | awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0; fflush()}' >> ${STEM}.log
  • 実行ログ
$ head job01.log
2018/05/04 03:32:01 2018-04-05 01:42:38 20170824-...
2018/05/04 03:32:01 2017-07-31 23:04:24 aws-...
2018/05/04 03:32:01 2017-05-01 18:30:11 aws-...