I've written a bash script to automate month-end data processing from a vendor to a MySQL DB located on my machine.
The script runs to completion but quite commonly errs out/omits a few of the sections, which I'm subsequently able to run successfully via the command line without modification. The error appears to be in the 2nd cURL call (included below). It's not clear to me what about running within a shell script would cause this issue when I'm able to run without issue from the command line.
I've also included a call made just prior, and associated status updates, which completes without issue.
Sample code
DATE=$(date +"%Y%m")
USER=/user/
PASS=/pass/
SDATE=/lastRunDate/
MON=`date "+%m"`
#Indicators Inc/Bal Statement Descriptions
URL=`curl -s 'https://www.quandl.com/api/v3/datatables/SHARADAR/INDICATORS?qopts.export=true&api_key=APIKEY' | jq -r '.datatable_bulk_download.file.link'`
curl $URL -o /media/E/data/qu/INDICATORS.zip
#SEP Equity prices
URL=`curl -s 'https://www.quandl.com/api/v3/datatables/SHARADAR/SEP?qopts.export=true&api_key=APIKEYG&date.gt='$SDATE'' | jq -r '.datatable_bulk_download.file.link'`
curl $URL -o /media/E/data/qu/SEP.zip
unzip -p /media/E/data/qu/SEP.zip > /media/E/mysql/mysql-files/sep.csv
mysql --user=$USER --password=$PASS -e "load data infile '/media/E/mysql/mysql-files/sep.csv' into table eq.prices fields terminated by ',' optionally enclosed by '\"' lines terminated by '\n' ignore 1 lines (ticker,date,open,high,low,close,@v,dividends,unadjClose,@dummy) set volume = if(@v is NULL or @v = '' or @v = ' ', 0, @v);"
rm /media/E/mysql/mysql-files/sep.csv
mv /media/E/data/qu/SEP.zip /media/E/data/qu/archive/SEP$DATE.zip
Update/Error Messages
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13089 100 13089 0 0 32478 0 --:--:-- --:--:-- --:--:-- 32478
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: null
mysql: [Warning] Using a password on the command line interface can be insecure.
mv: cannot stat '/media/E/data/qu/SEP.zip': No such file or directory