diff --git a/space-transfer.sh b/space-transfer.sh index e69f497..6631adf 100644 --- a/space-transfer.sh +++ b/space-transfer.sh @@ -26,7 +26,7 @@ function import_files { if [[ "$file" =~ ^eidf[a-zA-Z0-9]{2,5}-[a-zA-Z0-9]{3,8}-.+$ ]] && [[ -f "$filepath" ]]; then echo "File '$file' is formatted correctly" else - echo "IMPORT FAILED FOR '$file'. Incorrect formatting." | tee -a $TODAY_FAILURES + echo "IMPORT FAILED FOR '$file'. Incorrect formatting." | tee -a $TODAY_FAILURES continue fi @@ -59,9 +59,10 @@ function import_files { ;; esac + # Extra Check - If file has been modified in the last 3 minutes, don't move it if (( $(date +%s) - $(stat -c %Y "$LANDING_DIR/$file") < (6*3) )); then - echo "File $file modified in the last 3 minutes. Waiting for upload to complete" - continue + echo "File $file modified in the last 3 minutes. Waiting for upload to complete" + continue fi echo $project 'directory mounted at' $project_mount @@ -70,6 +71,9 @@ function import_files { read -r sha256 _ < <(/usr/bin/sha256sum "$filepath") printf '%s | %s\n' "$sha256" "$filepath" | tee -a $TODAY_INGRESS + # Extracts Windows/Linux from $project_mount and sets the 'environment' vairable + # This changes the moving path depending if window or Linux + local environment="${project_mount#/mnt/}" local environment="${environment%%/*}" @@ -78,11 +82,11 @@ function import_files { echo "IMPORT FAILED FOR FILE $file - Study could not be identified" continue else - echo "$LANDING_DIR/$file $project_mount/Import/$study" - mv $LANDING_DIR/$file $project_mount/Import/$study + echo "$LANDING_DIR/$file $project_mount/Import/$study" + mv $LANDING_DIR/$file $project_mount/Import/$study fi elif [[ $environment == "linux" ]]; then - echo "$filepath $project_mount/Import" + echo "$filepath $project_mount/Import" mv "$filepath" $project_mount/Import chown root:$project "$project_mount/Import/$file" else @@ -103,9 +107,9 @@ function export_files { local project="${project%%/Export/*}" if (( $(date +%s) - $(stat -c %Y $filepath) < (60*3) )); then - echo "File $file has been modified in the last 3 minutes. Waiting for write to complete" - continue - fi + echo "File $file has been modified in the last 3 minutes. Waiting for write to complete" + continue + fi echo "$file from $project will be exported" @@ -117,7 +121,7 @@ function export_files { echo $new_filename read -r sha256 _ < <(/usr/bin/sha256sum "$filepath") - printf '%s | %s\n' "$sha256" "$new_filename" | tee -a $TODAY_EGRESS + printf '%s | %s\n' "$sha256" "$new_filename" | tee -a $TODAY_EGRESS mv "$filepath" "$EXPORT_DIR/$new_filename" chgrp $project "$EXPORT_DIR/$new_filename" @@ -144,8 +148,8 @@ function export_files { if (( $(date +%s) - $(stat -c %Y $filepath) < (60*3) )); then echo "File $file has been modified in the last 3 minutes. Waiting for write to complete" - continue - fi + continue + fi echo "$file from $project will be exported" @@ -157,7 +161,7 @@ function export_files { echo "$file will be renamed $new_filename" read -r sha256 _ < <(/usr/bin/sha256sum "$filepath") - printf '%s | %s\n' "$sha256" "$new_filename" | tee -a $TODAY_EGRESS + printf '%s | %s\n' "$sha256" "$new_filename" | tee -a $TODAY_EGRESS if [[ "$file" == mft-* ]]; then mv "$filepath" "/mnt/os-transfer/windows-mft/$project/$study/Export/$new_filename"