Right I am trying to create a backup shell script for college but i am getting an error and since I know little about shell scripts i thought i'd ask for a bit of help. The error i am getting is :
I understand that means that there is something wrong with the ";;" at line 107 but i do not know what is wrong?
Here is my code
Thanks in advance
Stephen
./Script.sh: line 107: syntax error near unexpected token `;;'
./Script.sh: line 107: ` ;;'
I understand that means that there is something wrong with the ";;" at line 107 but i do not know what is wrong?
Here is my code
Code:
#!/bin/bash
# Stephen Ross' Backup Script
# declaring the variables and the path names
Backup=/Users/rosstephen/Documents/Archive_$(date '+%d.%m.%y:%H:%M').tgz
Restore=/Users/rosstephen/Documents
# begin while statement
while [1]
do
# user choice menu
clear
echo "***************************************************"
echo " Backup and Restore "
echo "***************************************************"
echo " Please select an option from 1-3:-"
echo
echo "1) Create a Backup"
echo
echo "2) Restore folders or files from a Backup"
echo
echo "3) Exit System"
echo
# Read user input
Read USERCHOICE
# begin the case statement
case $USERCHOICE in
'1') echo "Performing a Full Backup."
# pause for 2 seconds
sleep 2
echo "Please enter the complete pathname of the files that you would like to be backed up:-"
# read the user input and error correct path and on execution if it returns 0 t$
read LOCATION
if [ -d "$LOCATION" ]; then
echo "you are going to backup the selected files in "$LOCATION"
echo "the files or folders will be backed up to the location"
echo "folder named mybackups"
sleep 3
else
echo "That is an incorrect folder name, "
echo "please check that the directory is correct"
echo "then enter the folder or path name again remembering to be case sensitive."
read LOCATION
fi
# execute the backup
tar -cf $Backup $LOCATION
# check to see that the backup has completed correctly
if [ $? == 0 ]; then
echo "$Backup" has been successful."
sleep 3
else
echo "Your Backup could not be completed as a problem has occurred.."
sleep 3
fi
;;
'2') echo "You are about to restore files or folders from a backup"
sleep 3
echo "Listed below are any backups that are in the backup folder."
ls "$Restore"
echo "Please select the file you would like to restore"
echo "Please enter the full pathname."
read restorepath
if [ -f "$restorepath" ]; then
echo "the files will now be restored"
sleep 4
else
echo "An error has occurred with the filename entered."
echo "Please re-enter the file name carefully"
read restorepath
Restore="$Restore" "$restorepath";
Fi
echo "the files will now be restored"
sleep 4
tar -xf $Restore
if [ $? == 0 ]; then
echo "$restorepath" has been restored"
sleep 4
else
echo "There was an error during the restore"
echo "please try again or exit"
fi
;;
'3') echo "thank you, the program will now close "$USER"
exit
;;
*) echo "sorry try again select 1, 2 or 3 only"
echo "press enter to continue"
read -n 1
;;
esac
done
Thanks in advance
Stephen