# ----------------------------------------------------------------------------
# Script Author: Robert Holland
# Script Name: getfolders.sh
# Creation Date: Thu Jan 11 2024 09:00:40 GMT-0700 (US Mountain Standard Time)
# Last Modified: 20240423
# Copyright (c)2024
# Purpose: Use rsync to copy specified folders from one server to another.
# Source on using base 10: https://stackoverflow.com/questions/24777597/value-too-great-for-base-error-token-is-08
# ----------------------------------------------------------------------------

#!/bin/bash
parent=$1 #Parent folder
x=$2 #First argument
y=$3 #Second argument
z=0 #Zero constant to prepend to numbers less than 10

if [ $# -ne 3 ]
then
clear
echo "*************************************************************************"
echo "* Enter the folder range that you want to send."
echo "* Example to send folders 02 through 04 from the parent folder 202312."
echo "* Type: $0 202312 2 4"
echo "*************************************************************************"
else
while [[ $((10#$x)) -le $((10#$y)) ]]
do
if [ $x -lt 10 ]
then
echo "Synching folder $parent/$z$x." #Prepend zero in front of number less than 10.
rsync -av /media/rob/8C41-0A68/$parent/"$z$x" rob@servername.example.com:~/Music/all_communication/$parent/
else
echo "Synching folder $parent/$x."
rsync -av /media/rob/8C41-0A68/$parent/"$x" rob@servername.example.com:~/Music/all_communication/$parent/
fi
x=$(( 10#$x + 1 ))
done
echo "Some really cool message."
fi

#z=0
#if [ $1 -lt 10 ]
#then
#echo $z$1
#else
#echo $1
#fi