Skip to content

Commit

Permalink
Moved rstprod check before htar call. NOAA-EMC#1460
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidHuber-NOAA committed Oct 25, 2023
1 parent da05619 commit 5298b31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
13 changes: 7 additions & 6 deletions scripts/exgdas_enkf_earc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ if [ "${ENSGRP}" -eq 0 ]; then
fi

set +e
tar_fl=${ATARDIR}/${PDY}${cyc}/${RUN}.tar
${TARCMD} -P -cvf "${tar_fl}" $(cat "${ARCH_LIST}/${RUN}.txt")
status=$?

# Check if the newly created tarball has rstprod data in it
# Check if the tarball will have rstprod in it
has_rstprod="NO"
while IFS= read -r file; do
if [[ -f ${file} ]]; then
Expand All @@ -128,6 +124,11 @@ if [ "${ENSGRP}" -eq 0 ]; then
fi
done < "${ARCH_LIST}/${RUN}.txt"

# Create the tarball
tar_fl=${ATARDIR}/${PDY}${cyc}/${RUN}.tar
${TARCMD} -P -cvf "${tar_fl}" $(cat "${ARCH_LIST}/${RUN}.txt")
status=$?

# If rstprod was found, change the group of the tarball
if [[ "${has_rstprod}" == "YES" ]]; then
${HSICMD} chgrp rstprod "${tar_fl}"
Expand All @@ -143,7 +144,7 @@ if [ "${ENSGRP}" -eq 0 ]; then
fi
fi

# For safety, test if the htar/tar command failed after changing groups
# For safety, test if the htar/tar command failed only after changing groups
if (( status != 0 && ${PDY}${cyc} >= firstday )); then
echo "FATAL ERROR: ${TARCMD} ${tar_fl} failed"
exit "${status}"
Expand Down
41 changes: 22 additions & 19 deletions scripts/exglobal_archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,11 @@ if [[ ${HPSSARCH} = "YES" || ${LOCALARCH} = "YES" ]]; then
shopt -s extglob
for targrp in ${targrp_list}; do
set +e
tar_fl="${ATARDIR}/${PDY}${cyc}/${targrp}.tar"
${TARCMD} -P -cvf "${tar_fl}" $(cat "${ARCH_LIST}/${targrp}.txt")
status=$?

# Test gdas.tas and gdas_restarta.tar for rstprod and change group if so
# Test whether gdas.tar or gdas_restarta.tar will have rstprod data
has_rstprod="NO"
case ${targrp} in
'gdas'|'gdas_restarta')
has_rstprod="NO"
# Test for rstprod in each archived file
while IFS= read -r file; do
if [[ -f ${file} ]]; then
Expand All @@ -281,24 +278,30 @@ if [[ ${HPSSARCH} = "YES" || ${LOCALARCH} = "YES" ]]; then
fi
done < "${ARCH_LIST}/${targrp}.txt"

# Change group to rstprod if it was found
if [[ "${has_rstprod}" == "YES" ]]; then
${HSICMD} chgrp rstprod "${tar_fl}"
stat_chgrp=$?
${HSICMD} chmod 640 "${tar_fl}"
stat_chgrp=$((stat_chgrp+$?))
if [ "${stat_chgrp}" -gt 0 ]; then
echo "FATAL ERROR: Unable to properly restrict ${tar_fl}!"
echo "Attempting to delete ${tar_fl}"
${HSICMD} rm "${tar_fl}"
echo "Please verify that ${tar_fl} was deleted!"
exit "${stat_chgrp}"
fi
fi
;;
*) ;;
esac

# Create the tarball
tar_fl="${ATARDIR}/${PDY}${cyc}/${targrp}.tar"
${TARCMD} -P -cvf "${tar_fl}" $(cat "${ARCH_LIST}/${targrp}.txt")
status=$?

# Change group to rstprod if it was found even if htar/tar failed in case of partial creation
if [[ "${has_rstprod}" == "YES" ]]; then
${HSICMD} chgrp rstprod "${tar_fl}"
stat_chgrp=$?
${HSICMD} chmod 640 "${tar_fl}"
stat_chgrp=$((stat_chgrp+$?))
if [ "${stat_chgrp}" -gt 0 ]; then
echo "FATAL ERROR: Unable to properly restrict ${tar_fl}!"
echo "Attempting to delete ${tar_fl}"
${HSICMD} rm "${tar_fl}"
echo "Please verify that ${tar_fl} was deleted!"
exit "${stat_chgrp}"
fi
fi

# For safety, test if the htar/tar command failed after changing groups
if [[ "${status}" -ne 0 ]] && [[ "${PDY}${cyc}" -ge "${firstday}" ]]; then
echo "FATAL ERROR: ${TARCMD} ${tar_fl} failed"
Expand Down

0 comments on commit 5298b31

Please sign in to comment.