Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SRossi

macrumors regular
Original poster
May 27, 2009
202
0
Glasgow, Scotland
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 :

./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
 
Over-quoting on the prior line:
Code:
echo "thank you, the program will now close "$USER"

You have three "s. An odd number is not normally what you want.

-Lee
 
Thank you I have now took the quotes out of the file because I notice you dont need them I have also removed [1] from the while line at the top and now it is just running through the program.

Any help :)

Stephen
 
Thank you I have now took the quotes out of the file because I notice you dont need them I have also removed [1] from the while line at the top and now it is just running through the program.

Any help :)

Stephen

One quick thing to do is to run the script with debug output.
bash -x script.sh
 
One quick thing to do is to run the script with debug output.

Thanks I ran it like that but it still just runs through the whole script without allowing me to enter a number and when i do it just loops again.

Im actually so lost lol

Stephen
 
Ok I now have a new problem after I have archived the file it will not un archive, any help?

Thanks in advance again

Stephen
 
What errors are you getting now??

I'm not sure, but do you really want

Code:
tar -xf $Restore

in the restore section? I thought restorepath was the path to the tar file to untar. Do you want

Code:
tar -xf $restorepath

Also, just a side note, usually .tgz is a gzipped/tarred file, which you would use 'tar czf' and 'tar xzf' to tar/untar. I would either rename your file to just '.tar' or change your tar command to use the 'z' option. Since you are just using this internally it probably does not matter, but I think if you use 'tar cf' to create a tar file and someone uses 'tar xzf' to untar it, it won't work.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.