Skip to content

Instantly share code, notes, and snippets.

@ChristopherHogan
Created October 29, 2018 21:13
Show Gist options
  • Save ChristopherHogan/f80fddfcceda9d7ffe95a38fc7101a16 to your computer and use it in GitHub Desktop.
Save ChristopherHogan/f80fddfcceda9d7ffe95a38fc7101a16 to your computer and use it in GitHub Desktop.
Script to run on AWS startup
#!/bin/bash
PREFIX=/root/miniconda
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -p ${PREFIX}
CONDA=${PREFIX}/bin/conda
${CONDA} create -y -n mp -c chogan/label/dev -c chogan -c conda-forge pymeep boto3
BASE_FILENAME=$(date +%s.%N)
export LOGFILE=${BASE_FILENAME}.log
export PYSCRIPT=run_random_sim.py
PYTHON=${PREFIX}/envs/mp/bin/python
${PYTHON} -c "import boto3; import os; s3 = boto3.resource('s3'); s3.Bucket('hogan-fragment-stats').download_file(os.environ['PYSCRIPT'], os.environ['PYSCRIPT'])"
${PYTHON} ${PYSCRIPT} -f ${BASE_FILENAME}.csv > ${LOGFILE} 2>&1
${PYTHON} -c "import boto3; import os; s3 = boto3.client('s3'); s3.upload_file(os.environ['LOGFILE'], 'hogan-fragment-stats', 'logs/' + os.environ['LOGFILE']);"
shutdown -h now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment