Sample Header Ad - 728x90

While Loop Exits After Calling Function

1 vote
0 answers
19 views
I'm trying to do a db backup script using Bash. When adding a "Resume" feature to the script, I do the following loop calling defined functions to do step by step (depending on the .lock file contents). This is unexpected behavior since I have created a bunch of other scripts that follow the same logic on calling functions from a loop and they work correctly. My guess is it has something to do with the ssh command which is the difference throughout all the other scripts, but I just can't wrap my mind around it… ``` LOCK=restore.lock SERVER_BACKUP_FILE_NAME="backup" ... show_help() { ... } while getopts i:h opt; do case $opt in i) COMPANY_ID=$OPTARG;; h) show_help esac done ... backup() { if [ ! -z $COMPANY_ID ] then log_echo "Creating company backup file from production..." sleep 5 SOURCE_SERVER_IP=$(dig +short ${SOURCE_SERVER_HOST}) REMOTE_CMD="~/repository/scripts/database/backup.sh -i ${COMPANY_ID}; exit;" ssh ${SOURCE_SERVER_USER}@${SOURCE_SERVER_IP} "bash -l -c '${REMOTE_CMD}'" SERVER_BACKUP_FILE_NAME="backup_${COMPANY_ID}" fi sed "/\/d" -i ${LOCK} } download() { ... } import() { ... } # For some reason the backup() function breaks the while loop. restore() { while IFS= read -r FUNC; do eval $FUNC; done > ${LOCK} echo "download" >> ${LOCK} echo "import" >> ${LOCK} else log_echo "Resuming..." fi # Calling main function that loops through the .lock file containing the function names # to dynamically execute said functions. restore
Asked by James (111 rep)
Jul 19, 2024, 02:46 AM
Last activity: Jul 19, 2024, 03:03 AM