Skip to content

Commit

Permalink
Added logging for the automatic populatedb prod script
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi-salunkhe-mettle committed Aug 28, 2024
1 parent ccc02bb commit b15f956
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions scripts/automatic_populatedb_prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ EMAIL=

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
log_file="/etc/lantern/logs/automatic_populatedb_prod_logs.txt"
current_datetime=$(date +"%Y-%m-%d %H:%M:%S")

#update source data from endpoint source list and NPPES
cd ../resources/prod_resources
Expand All @@ -24,29 +26,33 @@ PASTNPPESFILE="https://download.cms.gov/nppes/NPPES_Data_Dissemination_${PASTMON
rm -f endpoint_pfile.csv
rm -f npidata_pfile.csv

echo "Downloading ${MONTH} NPPES Resources..."
curl -s -f -o temp.zip ${NPPESFILE} || echo "${MONTH} NPPES Resources not available, downloading ${PASTMONTH} NPPES Resources..." && curl -s -o temp.zip ${PASTNPPESFILE}
echo "Extracting endpoint and npidata files from NPPES zip file..."
echo "$current_datetime - Downloading ${MONTH} NPPES Resources..." >> $log_file
curl -s -f -o temp.zip ${NPPESFILE} || {
echo "$current_datetime - ${MONTH} NPPES Resources not available, downloading ${PASTMONTH} NPPES Resources..." >> $log_file && curl -s -o temp.zip ${PASTNPPESFILE}
}
echo "$current_datetime - Extracting endpoint and npidata files from NPPES zip file..." >> $log_file
unzip -q temp.zip endpoint_pfile\*.csv
unzip -q temp.zip npidata_pfile\*.csv
rm *fileheader.csv
mv endpoint_pfile*.csv endpoint_pfile.csv
mv npidata_pfile*.csv npidata_pfile.csv
rm temp.zip

echo "Removing all entries from npidata_pfile that are not Entity Type 2 (Organization)..."
echo "$current_datetime - Removing all entries from npidata_pfile that are not Entity Type 2 (Organization)..." >> $log_file
sed -E '/^[^,]*,[^,]*(\"1\"|\"\")/d' npidata_pfile.csv > npidata_pfile2.csv
rm npidata_pfile.csv
mv npidata_pfile2.csv npidata_pfile.csv

echo "Populating db with endpoint and NPPES information..."
echo "$current_datetime - Populating db with endpoint and NPPES information..." >> $log_file
cd ../../scripts
docker exec lantern-back-end_endpoint_manager_1 /etc/lantern/populatedb.sh || echo "Lantern failed to save endpoint information in database and download and save NPPES information." | /usr/bin/mail -s "Automatic prod database population error." ${EMAIL}

docker exec lantern-back-end_endpoint_manager_1 /etc/lantern/populatedb.sh || {
echo "$current_datetime - Lantern failed to save endpoint information in database and download and save NPPES information." >> $log_file
echo "Lantern failed to save endpoint information in database and download and save NPPES information." | /usr/bin/mail -s "Automatic prod database population error." ${EMAIL}
}
cd ../resources/prod_resources
rm -f endpoint_pfile.csv
rm -f endpoint_pfile
rm -f npidata_pfile.csv
rm -f npidata_pfile

echo "done"
echo "$current_datetime - done" >> $log_file

0 comments on commit b15f956

Please sign in to comment.