The test reports success even if the sftp command failed
Summary
The script reports success even if the transfer (sftp command) actually failed
Steps to reproduce
What is the current bug behavior?
- Initializing the automatic mode of the Transfer Tool... DONE
- Testing the connection to the remote server... DONE
- Compressing the viruses and bacteria subfolders... DONE
- Hashing and encrypting the archives... DONE
- Transferring the encrypted archives... DONE
DONE Transfer completed. 78 files has been securely transferred to the secured server.
Time: 25 s
DONE Test completed. Everything went smoothly.
What is the expected correct behavior?
- Initializing the automatic mode of the Transfer Tool... DONE
- Testing the connection to the remote server... DONE
- Compressing the viruses and bacteria subfolders... DONE
- Hashing and encrypting the archives... DONE
- Transferring the encrypted archives... ERROR
Relevant screenshots and/or logs
Uwe Schmidt uwe.schmitt@id.ethz.ch nicely fixed the bug with the following modifications:
diff --git a/spsp b/spsp
index b66d03f..c025451 100755
--- a/spsp
+++ b/spsp
@@ -437,9 +437,16 @@ autoMode() {
for FILE in *.*; do
if [ -f "$FILE" ]; then
- echo put "$FILE" | sftp -q -b- "${SFTP_URL}/$VIRUSES" 1>/dev/null 2>>"../../$ERRORLOGFILE"
- ((SUCCESS = SUCCESS + 1))
- echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE"
+ echo put "$FILE" | sftp -q -b- "${SFTP_URL}/$VIRUSES" 2>>"../../$ERRORLOGFILE" 1>&2
+ if [[ $$ -eq 0 ]]; then
+ ((SUCCESS = SUCCESS + 1))
+ echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE"
+ else
+ ((ERRORS = ERRORS + 1))
+ ((STEP_ERRORS = STEP_ERRORS + 1))
+ echo "[$(date +"%T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$LOGFILE"
+ echo "[$(date +"%F %T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$ERRORLOGFILE"
+ fi
if [[ "$*" == *--no-archive* ]] || [[ "$*" == *-NA* ]]; then
rm -rf "$FILE"
echo "[$(date +"%T")] local.SUCCESS: --NA activated, $FILE successfully removed" >>"../../$LOGFILE"
@@ -454,9 +461,16 @@ autoMode() {
for FILE in *.*; do
if [ -f "$FILE" ]; then
- echo put "$FILE" | sftp -q -b- -o LogLevel=QUIET "${SFTP_URL}/$BACTERIA" 1>/dev/null 2>>"../../$ERRORLOGFILE"
- ((SUCCESS = SUCCESS + 1))
- echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE"
+ echo put "$FILE" | sftp -q -b- "${SFTP_URL}/$BACTERIA" 2>>"../../$ERRORLOGFILE" 1>&2
+ if [[ $$ -eq 0 ]]; then
+ ((SUCCESS = SUCCESS + 1))
+ echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE"
+ else
+ ((ERRORS = ERRORS + 1))
+ ((STEP_ERRORS = STEP_ERRORS + 1))
+ echo "[$(date +"%T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$LOGFILE"
+ echo "[$(date +"%F %T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$ERRORLOGFILE"
+ fi
if [[ "$*" == *--no-archive* ]] || [[ "$*" == *-NA* ]]; then
rm -rf "$FILE"
echo "[$(date +"%T")] local.SUCCESS: --NA activated, $FILE successfully removed" >>"../../$LOGFILE"
@@ -473,16 +487,17 @@ autoMode() {
printf "${BACK_GREEN} DONE ${COL_RESET}\n"
fi
- if [[ $SUCCESS > 0 ]]; then
- printf "\n${BACK_GREEN} DONE ${COL_RESET} Transfer completed. $SUCCESS files has been securely transferred to the secured server.\n\n"
- fi
-
if [[ $ERRORS > 0 ]]; then
printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Completed with $ERRORS error(s)${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n"
printf "${BACK_RED} error ${COL_RESET} Error detected: Please check ./$ERRORLOGFILE\n"
exit 1
fi
+ if [[ $SUCCESS > 0 ]]; then
+ printf "\n${BACK_GREEN} DONE ${COL_RESET} Transfer completed. $SUCCESS files has been securely transferred to the secured server.\n\n"
+ fi
+
+
END=$(date +%s)
DIFF=$(($END - $START))
echo "Time: $DIFF s"