Hello, I have a script that will go to a backup server and check for a backup server for a specific domain. This is all within a specific function, the thing is, if for some reason the backup does not exist on that backup server, I want it to ask the user if they want to try a different backup server, read the input and go back to the section within the function where it asks for the server and goes from there. I tried a while loop but that breaks the script, and I also do not want to make another function with the same code in it as it gets too confusing then. How can I do this without making it too complex? Here is the section of the code. Remember, this code is inside of a function:
Code:
echo ""
echo "[Backup Servers]"
echo "----------------------------------------------------------------"
grep -ilR $host /root/server_backupserver/cron/ | cut -d. -f2
while [ ! $server ]
do
echo "----------------------------------------------------------------"
echo -n "Pick a Backup Server: "
read server
echo "----------------------------------------------------------------"
done
homedir=$(ssh $server crontab -l | grep $host | rev | cut -d\ -f 2 | rev)
exist1=`ssh $server "ls $homedir/$host/home/ | grep -c $username"`
if [ $exist1 -ge 1 ]
then
echo ""
echo "[Restore Dates]"
echo "----------------------------------------------------------------"
ssh $server "rdiff-backup -l $homedir/$host/home/$username"
while [ ! $date ]
do
echo "----------------------------------------------------------------"
echo -n "Pick a Restore (incremental): "
read date
echo "----------------------------------------------------------------"
done
ssh $server "rdiff-backup --force -v5 $homedir/$host/home/$username/rdiff-backup-data/$date $host::/home/$username"
else
echo ""
echo "----------------------------------------------------------------"
echo "Error: Backup for $username does not exist on $server. Do you want to try an alternate server?"
echo " 1) Yes "
echo " 2) No "
echo "----------------------------------------------------------------"
echo -n "Enter Option: "
read alt1
fi
See, at the bottom I want it to read alt1 and go to a specified point, while loop doesn't seem to work and errors out. Maybe I can use goto, I know it's not recommended, but can someone show how if this is the only option. Thanks for the help.