Skip to content

Commit

Permalink
Test tarballs for rstprod before calling chgrp (NOAA-EMC#1967)
Browse files Browse the repository at this point in the history
Certain tarballs may or may not contain `rstprod` data.  For instance, the first half cycle
gdas and enkfgdas tarballs will not contain `rstprod`, while future cycles likely will.  Also,
some systems do not have `rstprod` on them.  This will test the contents of the tarballs
first before attempting to change the group to rstprod.

Resolves NOAA-EMC#1460
  • Loading branch information
DavidHuber-NOAA authored Oct 26, 2023
1 parent c02e118 commit 9623688
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
37 changes: 33 additions & 4 deletions scripts/exgdas_enkf_earc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,41 @@ if [ "${ENSGRP}" -eq 0 ]; then
fi

set +e
${TARCMD} -P -cvf "${ATARDIR}/${PDY}${cyc}/${RUN}.tar" $(cat "${ARCH_LIST}/${RUN}.txt")
# Check if the tarball will have rstprod in it
has_rstprod="NO"
while IFS= read -r file; do
if [[ -f ${file} ]]; then
group=$( stat -c "%G" "${file}" )
if [[ "${group}" == "rstprod" ]]; then
has_rstprod="YES"
break
fi
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=$?
${HSICMD} chgrp rstprod "${ATARDIR}/${PDY}${cyc}/${RUN}.tar"
${HSICMD} chmod 640 "${ATARDIR}/${PDY}${cyc}/${RUN}.tar"

# If rstprod was found, change the group of the tarball
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 only after changing groups
if (( status != 0 && ${PDY}${cyc} >= firstday )); then
echo "FATAL ERROR: ${TARCMD} ${PDY}${cyc} ${RUN}.tar failed"
echo "FATAL ERROR: ${TARCMD} ${tar_fl} failed"
exit "${status}"
fi
set_strict
Expand Down
44 changes: 38 additions & 6 deletions scripts/exglobal_archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,49 @@ if [[ ${HPSSARCH} = "YES" || ${LOCALARCH} = "YES" ]]; then
shopt -s extglob
for targrp in ${targrp_list}; do
set +e
${TARCMD} -P -cvf "${ATARDIR}/${PDY}${cyc}/${targrp}.tar" $(cat "${ARCH_LIST}/${targrp}.txt")
status=$?

# Test whether gdas.tar or gdas_restarta.tar will have rstprod data
has_rstprod="NO"
case ${targrp} in
'gdas'|'gdas_restarta')
${HSICMD} chgrp rstprod "${ATARDIR}/${CDATE}/${targrp}.tar"
${HSICMD} chmod 640 "${ATARDIR}/${CDATE}/${targrp}.tar"
# Test for rstprod in each archived file
while IFS= read -r file; do
if [[ -f ${file} ]]; then
group=$( stat -c "%G" "${file}" )
if [[ "${group}" == "rstprod" ]]; then
has_rstprod="YES"
break
fi
fi
done < "${ARCH_LIST}/${targrp}.txt"

;;
*) ;;
esac
if [ "${status}" -ne 0 ] && [ "${PDY}${cyc}" -ge "${firstday}" ]; then
echo "FATAL ERROR: ${TARCMD} ${PDY}${cyc} ${targrp}.tar failed"

# 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"
exit "${status}"
fi
set_strict
Expand Down

0 comments on commit 9623688

Please sign in to comment.