Skip to content

Instantly share code, notes, and snippets.

@troyhill
Last active September 17, 2018 17:00
Show Gist options
  • Save troyhill/b77898e267937f6896ec3e0e9cf52e99 to your computer and use it in GitHub Desktop.
Save troyhill/b77898e267937f6896ec3e0e9cf52e99 to your computer and use it in GitHub Desktop.
R-bash integration: bash script
#!/bin/bash
# Script downloads NOAA station data and saves it to a .csv file
# Usage: ./bash/getNOAAdata.sh ./bash/getNOAAdata.R 8656483 8665530
if [ "$#" -lt 2 ]; then
echo "Usage: $0 R_script NOAA_station1 NOAA_station2 ..." 1>&2
exit 1
fi
Rscript=$1
time_stamp=$(date +%Y%m%d)
dir_name="./RDATA/NOAAdata/${time_stamp}"
# make a date-stamped parent directory for the station data
if [ ! -d $dir_name ]; then
mkdir -p $dir_name
echo $dir_name
fi
# Pull data using the R script
shift
for i in "$@"; do
$Rscript $i $dir_name
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment